uibarbuttonitem

How to set target and action for UIBarButtonItem at runtime

那年仲夏 提交于 2019-11-27 14:29:32
问题 Tried this but only works for UIButton: [btn setTarget:self action:@selector(btnClicked:) forControlEvents:UIControlEventTouchUpInside]; 回答1: Just set the UIBarButtonItem's target and action properties directly. 回答2: UIBarButtonItem doesnt have the same addTarget method so you have to set them directly as follows btn.target = self; btn.action = @selector(barButtonCustomPressed:); ... // can specify UIBarButtonItem instead of id for this case -(IBAction)barButtonCustomPressed:(UIBarButtonItem*

iOS Autolayout and UIToolbar/UIBarButtonItems

让人想犯罪 __ 提交于 2019-11-27 14:19:21
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 this be accomplished when using autolayout? snorock Autolayout constraints only work with UIViews and

UISearchBar cancel button color?

一曲冷凌霜 提交于 2019-11-27 11:19:19
问题 When I drop a UISearchBar into my view inside Interface Builder, and change its style to Black Opaque, the cancel button stays unfittingly blue / gray and doesn't become black. How can I make the cancel button black? EDIT: It does work like this: // Assume a UISearchBar searchBar. NSArray *subviews = [searchBar subviews]; // The index depends on how you configure the searchBar. UIButton *cancelButton = [subviews objectAtIndex:3]; // Set the style to "normal" style. [cancelButton setStyle:0];

Xcode 6 Storyboard Unwind Segue with Swift Not Connecting to Exit

和自甴很熟 提交于 2019-11-27 10:55:39
When trying to connect a Navigation Bar Button to the Exit item of a ViewController in Xcode 6 (not really sure if it's an Xcode 6 problem but worth mentioning as it is in beta) it does not find the Swift function in the custom class. The function it should be finding: @IBAction func unwindToList(segue: UIStoryboardSegue) { } I made another button on the view just to make sure I could get an IBAction working with Swift and that I was writing it correctly. This works fine: @IBAction func test(sender: AnyObject) { NSLog("Test") } I have seen this question that seems like the same issue but

How to set the action for a UIBarButtonItem in Swift

空扰寡人 提交于 2019-11-27 10:13:00
问题 How can the action for a custom UIBarButtonItem in Swift be set? The following code successfully places the button in the navigation bar: var b = UIBarButtonItem(title: "Continue", style: .Plain, target: self, action:nil) self.navigationItem.rightBarButtonItem = b Now, I would like to call func sayHello() { println("Hello") } when the button is touched. My efforts so far: var b = UIBarButtonItem(title: "Continue", style: .Plain, target: self, action:sayHello:) // also with `sayHello`

Multiple UIBarButtonItems in UINavigationBar

折月煮酒 提交于 2019-11-27 09:52:36
问题 How to Create multiple bar button in navigation bar? 回答1: You must use UIToolbar and set the toolbar with buttons: // create a toolbar where we can place some buttons UIToolbar *toolbar = [[UIToolbar alloc] initWithFrame:CGRectMake(0, 0, 100, 45)]; [toolbar setBarStyle: UIBarStyleBlackOpaque]; // create an array for the buttons NSMutableArray *buttons = [[NSMutableArray alloc] initWithCapacity:3]; // create a standard save button UIBarButtonItem *saveButton = [[UIBarButtonItem alloc]

Increase NavigationBar height

吃可爱长大的小学妹 提交于 2019-11-27 09:36:12
I have the following code: func navbarbutton() { UIView.animateWithDuration(0.2, animations: { () -> Void in let current = self.navigationController?.navigationBar.frame self.navigationController?.navigationBar.frame = CGRectMake(self.frame!.origin.x, self.frame!.origin.y, self.frame!.size.width, current!.size.height + 50) self.navigationController?.navigationBar.layoutIfNeeded() }) } I'm able to increase the height of the navigation bar by 50 dp. That's not the issue for me. The issue I'm having is that the UIBarButtonItems are all aligned to the bottom. How can I get them aligned to the top

How to remove all navigationbar back button title

偶尔善良 提交于 2019-11-27 09:34:34
问题 When I push a UIViewController , it has some title in back button at new UIViewController , if the title has a lot of text, It does not look good in iPhone 4s So I want to remove it. If I add some code in prepareForSegue function, it is going to be a trouble. Any better way to achieve this? 回答1: If you want back arrow so following code put into AppDelegate file into didFinishLaunchingWithOptions method. For Objective-C [[UIBarButtonItem appearance] setBackButtonTitlePositionAdjustment

UIBarButtonItem with custom image and no border

假装没事ソ 提交于 2019-11-27 09:11:56
问题 I want to create a UIBarButtonItem with a custom image, but I don't want the border that iPhone adds, as my Image has a special border. It's the same as the back button but a forward button. This App is for an inHouse project, so I don't care if Apple reject or approves it or likes it :-) If I use the initWithCustomView:v property of the UIBarButtonItem, I can do it: UIImage *image = [UIImage imageNamed:@"right.png"]; UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom]; [button

Change UIBarButtonItem from UISearchBar

我只是一个虾纸丫 提交于 2019-11-27 08:17:01
问题 I'd like to change the text font and color of the Cancel button inside the UISearchBar in iOS 8. I've tried the solutions for iOS 6 and 7 already and they don't seem to work. 回答1: This was not the solution I was looking for, but it worked. let cancelButtonAttributes: NSDictionary = [NSFontAttributeName: FONT_REGULAR_16!, NSForegroundColorAttributeName: COLOR_BLUE] UIBarButtonItem.appearance().setTitleTextAttributes(cancelButtonAttributes, forState: UIControlState.Normal) 回答2: What you are