How to create a custom tab bar controller with custom tab bar shape programattically Announcing the arrival of Valued Associate #679: Cesar Manara Planned maintenance scheduled April 23, 2019 at 23:30 UTC (7:30pm US/Eastern) Data science time! April 2019 and salary with experience The Ask Question Wizard is Live!How do I create delegates in Objective-C?How do I sort an NSMutableArray with custom objects in it?How to create CustomTabBarController using XIB?How to change Status Bar text color in iOSHow to hide tab bar with animation in iOS?Custom Tab Bar SwiftTab Bar Controller within Tab Bar ControllerSwitch tab bar view in subview programmatically (custom tab bar controller)Adding a custom UIViewcontroller to subview programmatically but getting an error message “Cannot convert value of type…”Swift: make custom progress view follow user tap? UIBezier
Why are two-digit numbers in Jonathan Swift's "Gulliver's Travels" (1726) written in "German style"?
How can I prevent/balance waiting and turtling as a response to cooldown mechanics
Pointing to problems without suggesting solutions
Did any compiler fully use 80-bit floating point?
What did Turing mean when saying that "machines cannot give rise to surprises" is due to a fallacy?
Does the universe have a fixed centre of mass?
An isoperimetric-type inequality inside a cube
Keep at all times, the minus sign above aligned with minus sign below
Flight departed from the gate 5 min before scheduled departure time. Refund options
Noise in Eigenvalues plot
Why not use the yoke to control yaw, as well as pitch and roll?
Why is there so little support for joining EFTA in the British parliament?
How could a hydrazine and N2O4 cloud (or it's reactants) show up in weather radar?
Marquee sign letters
As a dual citizen, my US passport will expire one day after traveling to the US. Will this work?
Does the transliteration of 'Dravidian' exist in Hindu scripture? Does 'Dravida' refer to a Geographical area or an ethnic group?
Diophantine equation 3^a+1=3^b+5^c
Twin's vs. Twins'
Where and when has Thucydides been studied?
One-one communication
Inverse square law not accurate for non-point masses?
How does the body cool itself in a stillsuit?
The test team as an enemy of development? And how can this be avoided?
Is there a verb for listening stealthily?
How to create a custom tab bar controller with custom tab bar shape programattically
Announcing the arrival of Valued Associate #679: Cesar Manara
Planned maintenance scheduled April 23, 2019 at 23:30 UTC (7:30pm US/Eastern)
Data science time! April 2019 and salary with experience
The Ask Question Wizard is Live!How do I create delegates in Objective-C?How do I sort an NSMutableArray with custom objects in it?How to create CustomTabBarController using XIB?How to change Status Bar text color in iOSHow to hide tab bar with animation in iOS?Custom Tab Bar SwiftTab Bar Controller within Tab Bar ControllerSwitch tab bar view in subview programmatically (custom tab bar controller)Adding a custom UIViewcontroller to subview programmatically but getting an error message “Cannot convert value of type…”Swift: make custom progress view follow user tap? UIBezier
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;
I am trying to create my iOS mobile app entirely in code. Doing so causes problems with my custom tab bar controller with a custom tab bar shape.
My custom tab bar shape looks something along the lines of this
AppDelegate.swift:
func application(_ application: UIApplication,
didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool
window = UIWindow()
window.rootViewController = CustomTabBarController()
window?.makeKeyAndVisible()
return true
In my Custom TabBarController:
import UIKit
class CustomTabBarController: UITabBarController
override func viewDidLoad()
super.viewDidLoad()
setupCenterButton()
func setupCenterButton()
let menuButton = UIButton(frame: CGRect(x: 0, y: 0, width: 64, height: 64))
var menuButtonFrame = menuButton.frame
menuButtonFrame.origin.y = view.bounds.height - menuButtonFrame.height - 48
menuButtonFrame.origin.x = view.bounds.width/2 - menuButtonFrame.size.width/2
menuButton.frame = menuButtonFrame
menuButton.clipsToBounds = true
menuButton.layer.cornerRadius = menuButtonFrame.height/2
view.addSubview(menuButton)
extension UITabBar
open override func sizeThatFits(_ size: CGSize) -> CGSize
return CGSize(width: size.width, height: 64)
And my custom tab bar shape
import UIKit
class CustomizedTabBar: UITabBar {
private var shapeLayer: CALayer?
private func addShape()
let shapeLayer = CAShapeLayer()
shapeLayer.path = createPath()
if let oldShapeLayer = self.shapeLayer
self.layer.replaceSublayer(oldShapeLayer, with: shapeLayer)
else
self.layer.insertSublayer(shapeLayer, at: 0)
self.shapeLayer = shapeLayer
func createPath() -> CGPath
let path = UIBezierPath()
path.move(to: CGPoint(x: 0, y: 0))
//..path moving around..
path.close()
return path.cgPath
override func point(inside point: CGPoint, with event: UIEvent?) -> Bool
//..stuff
override func draw(_ rect: CGRect)
self.addShape()
func createBezierPath() -> UIBezierPath
//..creating a path
How do I get around this? With the current code setup my tabbar comes out like a normal tabbar...not my custom shape
see here
and I have tried to override my tab bar property in my UITabBarController to return an instance of my CustomizedBarBar class, with no luck. Any help would be much appreciated!
ios swift uitabbarcontroller uitabbar
add a comment |
I am trying to create my iOS mobile app entirely in code. Doing so causes problems with my custom tab bar controller with a custom tab bar shape.
My custom tab bar shape looks something along the lines of this
AppDelegate.swift:
func application(_ application: UIApplication,
didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool
window = UIWindow()
window.rootViewController = CustomTabBarController()
window?.makeKeyAndVisible()
return true
In my Custom TabBarController:
import UIKit
class CustomTabBarController: UITabBarController
override func viewDidLoad()
super.viewDidLoad()
setupCenterButton()
func setupCenterButton()
let menuButton = UIButton(frame: CGRect(x: 0, y: 0, width: 64, height: 64))
var menuButtonFrame = menuButton.frame
menuButtonFrame.origin.y = view.bounds.height - menuButtonFrame.height - 48
menuButtonFrame.origin.x = view.bounds.width/2 - menuButtonFrame.size.width/2
menuButton.frame = menuButtonFrame
menuButton.clipsToBounds = true
menuButton.layer.cornerRadius = menuButtonFrame.height/2
view.addSubview(menuButton)
extension UITabBar
open override func sizeThatFits(_ size: CGSize) -> CGSize
return CGSize(width: size.width, height: 64)
And my custom tab bar shape
import UIKit
class CustomizedTabBar: UITabBar {
private var shapeLayer: CALayer?
private func addShape()
let shapeLayer = CAShapeLayer()
shapeLayer.path = createPath()
if let oldShapeLayer = self.shapeLayer
self.layer.replaceSublayer(oldShapeLayer, with: shapeLayer)
else
self.layer.insertSublayer(shapeLayer, at: 0)
self.shapeLayer = shapeLayer
func createPath() -> CGPath
let path = UIBezierPath()
path.move(to: CGPoint(x: 0, y: 0))
//..path moving around..
path.close()
return path.cgPath
override func point(inside point: CGPoint, with event: UIEvent?) -> Bool
//..stuff
override func draw(_ rect: CGRect)
self.addShape()
func createBezierPath() -> UIBezierPath
//..creating a path
How do I get around this? With the current code setup my tabbar comes out like a normal tabbar...not my custom shape
see here
and I have tried to override my tab bar property in my UITabBarController to return an instance of my CustomizedBarBar class, with no luck. Any help would be much appreciated!
ios swift uitabbarcontroller uitabbar
I am not sure but try to add layer as mask.
– Prashant Tukadiya
Mar 9 at 4:43
Please show us the code where are you using yourCustomizedBarBar
with default tab bar.
– Amber K
Mar 9 at 6:00
add a comment |
I am trying to create my iOS mobile app entirely in code. Doing so causes problems with my custom tab bar controller with a custom tab bar shape.
My custom tab bar shape looks something along the lines of this
AppDelegate.swift:
func application(_ application: UIApplication,
didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool
window = UIWindow()
window.rootViewController = CustomTabBarController()
window?.makeKeyAndVisible()
return true
In my Custom TabBarController:
import UIKit
class CustomTabBarController: UITabBarController
override func viewDidLoad()
super.viewDidLoad()
setupCenterButton()
func setupCenterButton()
let menuButton = UIButton(frame: CGRect(x: 0, y: 0, width: 64, height: 64))
var menuButtonFrame = menuButton.frame
menuButtonFrame.origin.y = view.bounds.height - menuButtonFrame.height - 48
menuButtonFrame.origin.x = view.bounds.width/2 - menuButtonFrame.size.width/2
menuButton.frame = menuButtonFrame
menuButton.clipsToBounds = true
menuButton.layer.cornerRadius = menuButtonFrame.height/2
view.addSubview(menuButton)
extension UITabBar
open override func sizeThatFits(_ size: CGSize) -> CGSize
return CGSize(width: size.width, height: 64)
And my custom tab bar shape
import UIKit
class CustomizedTabBar: UITabBar {
private var shapeLayer: CALayer?
private func addShape()
let shapeLayer = CAShapeLayer()
shapeLayer.path = createPath()
if let oldShapeLayer = self.shapeLayer
self.layer.replaceSublayer(oldShapeLayer, with: shapeLayer)
else
self.layer.insertSublayer(shapeLayer, at: 0)
self.shapeLayer = shapeLayer
func createPath() -> CGPath
let path = UIBezierPath()
path.move(to: CGPoint(x: 0, y: 0))
//..path moving around..
path.close()
return path.cgPath
override func point(inside point: CGPoint, with event: UIEvent?) -> Bool
//..stuff
override func draw(_ rect: CGRect)
self.addShape()
func createBezierPath() -> UIBezierPath
//..creating a path
How do I get around this? With the current code setup my tabbar comes out like a normal tabbar...not my custom shape
see here
and I have tried to override my tab bar property in my UITabBarController to return an instance of my CustomizedBarBar class, with no luck. Any help would be much appreciated!
ios swift uitabbarcontroller uitabbar
I am trying to create my iOS mobile app entirely in code. Doing so causes problems with my custom tab bar controller with a custom tab bar shape.
My custom tab bar shape looks something along the lines of this
AppDelegate.swift:
func application(_ application: UIApplication,
didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool
window = UIWindow()
window.rootViewController = CustomTabBarController()
window?.makeKeyAndVisible()
return true
In my Custom TabBarController:
import UIKit
class CustomTabBarController: UITabBarController
override func viewDidLoad()
super.viewDidLoad()
setupCenterButton()
func setupCenterButton()
let menuButton = UIButton(frame: CGRect(x: 0, y: 0, width: 64, height: 64))
var menuButtonFrame = menuButton.frame
menuButtonFrame.origin.y = view.bounds.height - menuButtonFrame.height - 48
menuButtonFrame.origin.x = view.bounds.width/2 - menuButtonFrame.size.width/2
menuButton.frame = menuButtonFrame
menuButton.clipsToBounds = true
menuButton.layer.cornerRadius = menuButtonFrame.height/2
view.addSubview(menuButton)
extension UITabBar
open override func sizeThatFits(_ size: CGSize) -> CGSize
return CGSize(width: size.width, height: 64)
And my custom tab bar shape
import UIKit
class CustomizedTabBar: UITabBar {
private var shapeLayer: CALayer?
private func addShape()
let shapeLayer = CAShapeLayer()
shapeLayer.path = createPath()
if let oldShapeLayer = self.shapeLayer
self.layer.replaceSublayer(oldShapeLayer, with: shapeLayer)
else
self.layer.insertSublayer(shapeLayer, at: 0)
self.shapeLayer = shapeLayer
func createPath() -> CGPath
let path = UIBezierPath()
path.move(to: CGPoint(x: 0, y: 0))
//..path moving around..
path.close()
return path.cgPath
override func point(inside point: CGPoint, with event: UIEvent?) -> Bool
//..stuff
override func draw(_ rect: CGRect)
self.addShape()
func createBezierPath() -> UIBezierPath
//..creating a path
How do I get around this? With the current code setup my tabbar comes out like a normal tabbar...not my custom shape
see here
and I have tried to override my tab bar property in my UITabBarController to return an instance of my CustomizedBarBar class, with no luck. Any help would be much appreciated!
ios swift uitabbarcontroller uitabbar
ios swift uitabbarcontroller uitabbar
edited Mar 9 at 3:22
asteezy24
asked Mar 9 at 0:54
asteezy24asteezy24
61
61
I am not sure but try to add layer as mask.
– Prashant Tukadiya
Mar 9 at 4:43
Please show us the code where are you using yourCustomizedBarBar
with default tab bar.
– Amber K
Mar 9 at 6:00
add a comment |
I am not sure but try to add layer as mask.
– Prashant Tukadiya
Mar 9 at 4:43
Please show us the code where are you using yourCustomizedBarBar
with default tab bar.
– Amber K
Mar 9 at 6:00
I am not sure but try to add layer as mask.
– Prashant Tukadiya
Mar 9 at 4:43
I am not sure but try to add layer as mask.
– Prashant Tukadiya
Mar 9 at 4:43
Please show us the code where are you using your
CustomizedBarBar
with default tab bar.– Amber K
Mar 9 at 6:00
Please show us the code where are you using your
CustomizedBarBar
with default tab bar.– Amber K
Mar 9 at 6:00
add a comment |
1 Answer
1
active
oldest
votes
Please try and run this way, and let me know.
class MyTab: UITabBar
class MyTabBarController: UITabBarController
override var tabBar: UITabBar
return MyTab()
I tried this with no luck
– asteezy24
Mar 9 at 20:49
add a comment |
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55072940%2fhow-to-create-a-custom-tab-bar-controller-with-custom-tab-bar-shape-programattic%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
Please try and run this way, and let me know.
class MyTab: UITabBar
class MyTabBarController: UITabBarController
override var tabBar: UITabBar
return MyTab()
I tried this with no luck
– asteezy24
Mar 9 at 20:49
add a comment |
Please try and run this way, and let me know.
class MyTab: UITabBar
class MyTabBarController: UITabBarController
override var tabBar: UITabBar
return MyTab()
I tried this with no luck
– asteezy24
Mar 9 at 20:49
add a comment |
Please try and run this way, and let me know.
class MyTab: UITabBar
class MyTabBarController: UITabBarController
override var tabBar: UITabBar
return MyTab()
Please try and run this way, and let me know.
class MyTab: UITabBar
class MyTabBarController: UITabBarController
override var tabBar: UITabBar
return MyTab()
answered Mar 9 at 6:03
Amber KAmber K
408315
408315
I tried this with no luck
– asteezy24
Mar 9 at 20:49
add a comment |
I tried this with no luck
– asteezy24
Mar 9 at 20:49
I tried this with no luck
– asteezy24
Mar 9 at 20:49
I tried this with no luck
– asteezy24
Mar 9 at 20:49
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55072940%2fhow-to-create-a-custom-tab-bar-controller-with-custom-tab-bar-shape-programattic%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
I am not sure but try to add layer as mask.
– Prashant Tukadiya
Mar 9 at 4:43
Please show us the code where are you using your
CustomizedBarBar
with default tab bar.– Amber K
Mar 9 at 6:00