uibarbuttonitem

Adding a UILabel to a UIToolbar

冷暖自知 提交于 2019-11-26 19:29:14
I'm trying to add a label to my toolbar. Button works great, however when I add the label object, it crashes. Any ideas? UIBarButtonItem *setDateRangeButton = [[UIBarButtonItem alloc] initWithTitle:@"Set date range" style:UIBarButtonItemStyleBordered target:self action:@selector(setDateRangeClicked:)]; UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(5, 5, 20, 20)]; label.text = @"test"; [toolbar setItems:[NSArray arrayWithObjects:setDateRangeButton,label, nil]]; // Add the toolbar as a subview to the navigation controller. [self.navigationController.view addSubview:toolbar]; //

Change position of UIBarButtonItem in UINavigationBar

你。 提交于 2019-11-26 19:28:44
How can I change the position of a UIBarButtonItem in a UINavigationBar? I would like my button to be about 5px higher than its normal position. There is no particularly good way to do this. Your best bet if you really must is to subclass UINavigationBar, and override layoutSubviews to call [super layoutSubviews] and then find and reposition the button's view. This code creates a back button for UINavigationBar with image background and custom position. The trick is to create an intermediate view and modify its bounds. UIButton *backBtn = [UIButton buttonWithType:UIButtonTypeCustom]; UIImage

UIBarButtonItem in navigation bar programmatically?

橙三吉。 提交于 2019-11-26 19:22:17
I've been looking around for this solution for a while but haven't got any. e.g one solution is self.navigationItem.setRightBarButtonItem(UIBarButtonItem(barButtonSystemItem: .Stop, target: self, action: nil), animated: true) This code will add a button with "stop" image. Just like this, there are other solutions with "search, "refresh" etc. But what if I want to add a button programmatically with the image I want? Custom button image without setting button frame: You can use init(image: UIImage?, style: UIBarButtonItemStyle, target: Any?, action: Selector?) to initializes a new item using the

Change font of back navigation bar button

一曲冷凌霜 提交于 2019-11-26 19:21:44
问题 I want to be able to set the font of my apps navigation bar back button without doing anything too crazy and without losing any other design characteristics of the button (i.e. I want to keep the arrow). Right now I use this in viewDidAppear: to set the font of the normal bar button items. for (NSObject *view in self.navigationController.navigationBar.subviews) { if ([view isKindOfClass:[UIButton class]]) { [((UIButton*)view).titleLabel setFont:[UIFont fontWithName:@"Gill Sans" size:14.0]]; }

Add button to navigationbar programmatically

会有一股神秘感。 提交于 2019-11-26 19:00:46
问题 Hi I need to set the button on right side, in navigation bar, programatically , so that if I press the button I will perform some actions. I have created the navigation bar, programatically by; navBar=[[UINavigationBar alloc]initWithFrame:CGRectMake(0,0,320,44) ]; Similarly, I need to add the button, on the right side of this navigation bar. For that I used, 1. UIView* container = [[UIView alloc] init]; // create a button and add it to the container UIButton* button = [[UIButton alloc]

Removing the title text of an iOS UIBarButtonItem

ε祈祈猫儿з 提交于 2019-11-26 18:04:52
What I wanted to do is to remove the text from the 'Back' button of a UIBarButtonItem , leaving only the blue chevron on the navigation bar. Keep in mind that I'm developing for iOS 7. I've tried several methods, including, but not limited to: This is the image method which I did not like (the image looked out of place): UIBarButtonItem *barBtnItem = [[UIBarButtonItem alloc]initWithImage:[UIImage imageNamed:@"iOS7BackButton"] style:UIBarButtonItemStylePlain target:self action:@selector(goToPrevious:)]; self.navigationItem.leftBarButtonItem = barBtnItem; Another method I tried was this, which

How to Edit Empty Spaces of Left, Right UIBarButtonItem in UINavigationBar [iOS 7]

一曲冷凌霜 提交于 2019-11-26 17:04:16
I was using iOS 6.1 earlier, but now I have moved to iOS 7. Along with other problems, I have observed that in my navigation bar, the left space of left bar button item and right empty space of the right button bar item are quite more in IOS 7 than in iOS 6. I need to know is there a way I can reduce empty spaces of left, right bar button items in navigation bar?? Thanks in advance. Adnan Aftab I was also facing this problem. I also have feelings that in iOS 7 there is more space. And I figured out that this is about 10 points more. I usually use negative spaces when I want for

How to tint UIBarButtonItem background color? [duplicate]

Deadly 提交于 2019-11-26 16:56:41
问题 This question already has answers here : UIToolbar tint on iOS 4 (2 answers) Closed 3 months ago . I have a UIToolbar that contains 2 buttons. The toolbar has a tint: toolbar.tintColor = [UIColor colorWithRed:(102.0/255.0) green:(20.0/255.0) blue:(11.0/255.0) alpha:1]; How can I make the buttons have a similar tint color? 回答1: I found this solution preferable to those listed here: Tint UIButton and UIBarButtonItem. Unlike the accepted answer, it allows you to change the color of

setting image for UIBarButtonItem - image stretched

风格不统一 提交于 2019-11-26 16:49:12
问题 When I try to use UIBarButtonItem's "initWithImage" to initialize a navigation bar custom image, it comes out washed-up and stretched against a black navigation bar. This is how I create it: UIBarButtonItem *button = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"gear.png"] style:UIBarButtonItemStyleBordered target:self action:@selector(showSetting:)]; Here is what it looks like: Any idea if it's a problem with the image? I got it from a set of icons I bought. 回答1: The displayed

iOS Autolayout and UIToolbar/UIBarButtonItems

你说的曾经没有我的故事 提交于 2019-11-26 16:41:09
问题 I have an iOS view with autolayout enabled and have a UIToolbar with a UISearchBar and UISegmentControl contained with the toolbar. I want the UISearchBar to have a flexible width so I need to add a constraint to force this, but from what I can tell you cannot add constraints to items in a UIToolbar in Interface Builder. The options are all disabled. Before AutoLayout I would accomplish this with autoresizingmasks . Are constraints not allowed within UIToolbars/UINavigationBars ? How else can