ios7,uibutton,nsattributedstring , UIButton with multi-line titleLabel with NSAttributedString doesn't work in iOS 7 but works in iOS8


UIButton with multi-line titleLabel with NSAttributedString doesn't work in iOS 7 but works in iOS8

Question:

Tag: ios7,uibutton,nsattributedstring

In my project i have a requirement to show a UIButton that has two lines of text in its titleLabel With NSAttributedString. Its working fine in iOS8 but Where as in iOS7 its not working,i can see two lined text after selected button.

This is the code I'm using:

calendarBtn= [UIButton buttonWithType:UIButtonTypeCustom];
calendarBtn.frame=CGRectMake(50 ,10, 45, 45);
[calendarBtn addTarget:self action:@selector(calendarBtnclicked:)forControlEvents:UIControlEventTouchUpInside];
calendarBtn.titleLabel.lineBreakMode = NSLineBreakByWordWrapping;
calendarBtn.titleLabel.textAlignment = NSTextAlignmentCenter;
calendarBtn.titleLabel.numberOfLines=2;
[calendarBtn setTitleColor:BLACK_COLOR forState:UIControlStateNormal];


NSString *[email protected]"27\nApr";
dateString=[dateString uppercaseString];
[calendarBtn setTitle:dateString forState:UIControlStateNormal];


// Font For 27
UIFont *ddFont = [UIFont fontWithName:ArkitechLight size:17.0f];

NSMutableDictionary *ddDict = [NSMutableDictionary dictionaryWithObject:ddFont forKey:NSFontAttributeName];
NSMutableParagraphStyle *style  = [[NSMutableParagraphStyle alloc] init];
[style setLineSpacing:3];
style.alignment=NSTextAlignmentCenter;
[style setLineBreakMode:NSLineBreakByWordWrapping];
[ddDict addEntriesFromDictionary:@{NSParagraphStyleAttributeName : style,}];

NSMutableAttributedString *ddStr = [[NSMutableAttributedString alloc] initWithString:[dateString substringToIndex:2] attributes:ddDict];

// Font For Apr
UIFont *mmmFont = [UIFont fontWithName:ArkitechLight size:11.5f];
NSDictionary *mmmDict = [NSDictionary dictionaryWithObject:mmmFont forKey:NSFontAttributeName];
NSMutableAttributedString *mmmString = [[NSMutableAttributedString alloc]initWithString:[dateString substringFromIndex:2] attributes:mmmDict];
[ddStr appendAttributedString:mmmString];

calendarBtn.titleLabel.attributedText=ddStr;

Answer:

You need to use this line to set attributed title

[calendarBtn setAttributedTitle: ddStr forState:UIControlStateNormal];

instead of

calendarBtn.titleLabel.attributedText=ddStr;

Hope it helps :)


Related:


UIView hides Navigation bar back button text how to make it visible?


swift,ios7,xamarin.forms
I am trying to change Navigation bar background to Gradient Red. I have added subview to navigation bar which sets background to Color I want. but then Navigation bar back button Text is invisible. Back button is visible but Text is not Visible. UIView view = new UIView(); var gradient...

UIButton with single press and long press events swift


ios,iphone,swift,uibutton
I want to trigger two action on button click and button long click. I have add a UIbutton in my interface builder. How can i trigger two action using IBAction can somebody tell me how to archive this ? this is the code i have used for a button click...

Swift - UIButton with two lines of text


ios,swift,uibutton
I was wondering if it is possible to create a UIButton with two lines of text. I need each line to have a different font size. The first line will be 17 point and the second will be 11 point. I've tried messing with putting two labels inside of a...

What does this auto layout error mean?


ios7,ios8,autolayout
I recently was trying to making my IOS 8 app built, with swift, become compatible with IOS 7 devices, but I've been running into some minor issues. I've fixed most of them, but I can't seem to find this error on the web or anything close to it. Can anyone...

this class is not key value coding-compliant for the key itemname


ios,objective-c,iphone,core-data,ios7
What I am trying to do is take the text that is in my uitextfield called editItemField and write the value in the NSString called toDoItemName to my core data model with the attribute named itemname. Im getting the above error. My core data model has one attribute named itemname...

Swift - How to properly architect buttons in MVC?


ios,swift,uiview,uibutton,segue
I had wrote a block of code which made a UIButtons in a UIView with a segue action all in the ViewController file. The segue action allows the user to press on the a UIButton and pushes a new UIView with the title of that button on it. This worked...

UIButton creating error - “unrecognized selector sent to instance”


swift,uibutton
I have added a button to my view using this code, however it comes up with the error "unrecognized selector sent to instance" and crashes the app. Does anyone know why this is ? Many thanks! let button: UIButton = UIButton(frame: CGRectMake(100, 400, 100, 50)) button.backgroundColor = UIColor.clearColor() button.setTitle("go Back",...

Simple animation not working on iOS7


objective-c,animation,ios7
Im using a button to trigger the following animation: newPosition1=CGPointMake(200.0f + _btnAgregar.frame.size.width/2.0f, _btnAgregar.center.y); [UIView animateWithDuration:0.5f animations:^{ _btnAgregar.center=newPosition1; }]; It works just fine on any device running on iOS8, but does absolutely nothing when running on iOS7. Any idea why? Thanks....

iOS : How to test app on real device without spend $99 buying an account[using Xcode7] [on hold]


ios,xcode,ios7,apple,xcode7
I am a new iOS developer. I am not rich , I wonder can I test my app on real device without spending $99 buying an account? Update I mean how to use Xcode7 to do this ? (step-by-step tutorial will be better Thx!)...

When building to mobile the size of fonts reduce and became very small


c#,user-interface,unity3d,uibutton,unityscript
Like I said in the title when i built to mobile the letter became too small. I think it is because phone has more pixel for his little screen. Well I tried to fix text by simply making text to images in photoshop. But how can I make InputFields text...

Custom UIButton Swift 2.0


ios,swift,uibutton,ios9
I am trying to convert my project to Swift 2.0. I have a custom UIButton that is now causing an error when I try to build. My code is: var myButton = MyCustomButton.buttonWihType(.Custom) as UIButton This is working with my project in Swift 1.2 but now does not work. The...

UIButton Text Only Appearing On Touch


ios,swift,uibutton
I've set up a UIButton as follows: let scanButton = UIButton() func setUpScanButton (scanButton: UIButton) -> () { scanButton.addTarget(self, action: "goToScanner" , forControlEvents: UIControlEvents.TouchUpInside) scanButton.backgroundColor = UIColor.greenColor() scanButton.setTitleColor(UIColor.blackColor(), forState: UIControlState.Normal) scanButton.setTitle("Scan", forState: UIControlState.Normal) scanButton.frame = CGRectMake(36, 385, self.view.frame.width - 41, 30) scanButton.center.x = CGRectGetMidX(self.view.bounds)...

Unwanted Invisible detection area around UIButton when Highlighted


ios,iphone,xcode,swift,uibutton
I am creating a "yes" and "no" UIButton in a universal device app in my viewDidLoad, like so: let yesUnpressedTexture = UIImage(contentsOfFile:NSBundle.mainBundle().resourcePath!.stringByAppendingPathComponent("yesButtonUnpressed.png"))! let yesPressedTexture = UIImage(contentsOfFile:NSBundle.mainBundle().resourcePath!.stringByAppendingPathComponent("yesButtonPressed.png"))! let buttonWidth = yesUnpressedTexture.size.width var yesButton = UIButton.buttonWithType(UIButtonType.Custom) as! UIButton...

IBAction Button Press (Don't want to see the press)


ios,uibutton,ibaction
So I have a few buttons in an application and obviously they can all be pressed and do various things... My question is, how can you "not display" the colour change or visual aid that happens on screen once a button is pressed? To be honest, I'm not sure how...

How do I ensure that the text entered into a UIAlertview transforms the text of a UIButton and STAYS that way after exiting and reentering the app


ios,objective-c,uibutton,constraints,nsuserdefaults
TL;DR : Open iOS app Enter a promo code Close app Open app Actual Results: Promo code box is out of wack (see images) Expected Results: Promo code should still be displayed So I've got a UIButton whose text keeps changing after the user clicks on it and exits and...

Calling prepareforSegue from a UIButton?


ios,swift,uitableview,uibutton,segue
I am trying to call a prepareForSegue function out of TableViewController from a button in an UITableViewCell. Can I just call it from the button? Something like: TableViewcontroller: func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject!) { if (segue.identifier == "segueExercise") { print(segue.identifier) let vc = segue.destinationViewController as! DetailViewController TableViewCell: @IBAction func exerciseAction(sender:...

How to change image of UIImageView that is inside a UIButton programatically?


ios,objective-c,iphone,uiimageview,uibutton
I created a UIButton with UIImageView and UILabel by the help of this question and answer by Tim and now I want change the image of the UIImageView on the button click event. I tried [sender.imageView setImage:image] but it not working

How to shrink a rectangular round cornered UIButton to a circular UIButton?


objective-c,iphone,uibutton,core-animation
With the help of this i was able to shrink the UIButton but atlast i want the UIButton to get rounded.Please help me to get the desired animation in sign up button. The code snippet is : Follow the link : https://www.dropbox.com/s/rh4tdub3zabxp2j/shot.gif?dl=0 self.buttonShrink = [CAKeyframeAnimation animationWithKeyPath:@"transform"]; self.buttonShrink.duration = .2f; self.buttonShrink.values...

Remove “heightForRowAtIndexPath” for iOS8


ios,ios7,ios8,deprecated,heightforrowatindexpath
I'm trying to solve this problem for two days before finding the solution. Here it is. ====== Hi everyone, I actually manage the height of my tableViewCell in iOS7 with the delegate method heightForRowAtIndexPath: Now, in iOS8 I use the property tableView.rowHeight = UITableViewAutomaticDimension with autolayout and it works great...

Centralise the title of UIButton as show in the Image Below Swift


ios,swift,uibutton,text-alignment
I want to show Button title like this but my output is comming like this even after centralising the title frmbtn is the outlet of button And the Code I am Using for this is frmbtn.setTitle("From Station\nSTN\nSTATION NAME", forState: UIControlState.Normal) frmbtn.titleLabel!.numberOfLines = 3 frmbtn.contentHorizontalAlignment = UIControlContentHorizontalAlignment.Center And Can we put...

Set custom attribute on button


ios,swift,uibutton
How can i set custom attributes on an button that is programmatically created? I have this code to create an button: var btn = UIButton(frame: CGRectMake(CGFloat(7 + add), 565, 39, 55)) btn.setTitle(String(Array(shuffledWord)[i...i]), forState: UIControlState.Normal) btn.addTarget(self, action: "btnPressed:", forControlEvents: UIControlEvents.TouchUpInside) btn.tag = 7 + add; I can give some value to...

In ios 8 push notification not showing me badges for current app


php,ios,iphone,ios7,push-notification
Hello friends i am new in push notification please help me out. I am trying to get badge count for my app but "NSDictionary userInfo" contains only alert and sound . this is the code for register device for push notification -(BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { if ([[UIApplication sharedApplication] respondsToSelector:@selector(registerUserNotificationSettings:)])...

Checking UIButton Image


ios,objective-c,uibutton
I am trying to check some UIButton images to see if they are certain images. If they are, I want to set an NSString to a value but the value is always null. What am I doing wrong? if ([self.firstButton.currentImage isEqual:[UIImage imageNamed:@"image"]] && [self.secondButton.currentImage isEqual:[UIImage imageNamed:@"another_image"]] && [self.thirdButton.currentImage isEqual:[UIImage imageNamed:@"another_image"]]...

Changing titles on buttons with custom NSString


ios,objective-c,uibutton
I need to change the title of a button, but the title of the button needs to change depending on the index of the NSArray I choose. How do I do that? Code: NSArray * answerChoiceArray1 = @[@"1492", @"13", @"Spain", @"1678", @"1775", @"1848", @"1899", @"1908", @"1928", @"1999", @"12,000s BCE", @"Caral",...

How to dynamically add an action to a UIButton


ios,swift,uibutton
I noticed I had a lot of functions to dynamically add buttons in one of my view controllers, which clearly goes against the DRY principle. To fix this, I wrote a hit-everything configureButton function: func configureButton (button: UIButton, action: String, title: String, pos: [CGFloat]) { button.addTarget(self, action: action, forControlEvents: UIControlEvents.TouchUpInside)...

How to add directions among two custom locations in Mapview for IOS 7 (objective c)


objective-c,ios7,ios8,mkmapview
I have to add directions among two custom locations in IOS 7. Any one tell me please. Thanks. ...

Draw attention to and foster discovery of actionable controls


ios,ios8,uibutton
In an attempt to defer to content, I chose not to use any (navigation or tool) bars. The app has a tinted UIButton which brings up an action sheet (where the user could share the content, and adjust preferences). What I've seen is that people don't interact with the button....

Swift: Set UIButton Image with CGRect


ios,swift,uibutton,cgrect,uigraphicscontext
I'd like to set the image of a UIButton, but without creating all of the assets at different sizes. Since it should be just a grey rectangle, with some text on top, I'm trying to do this by creating a CGRect. The title is displayed as desired, and the button...

UIButton with pushViewController that is declared in another class


ios,objective-c,uiviewcontroller,uibutton
Hi everyone I am trying to add a custom nav bar that is declared in a different class and has a button that make a push action. My initial problem was that when the app was pushing the view because of the uinavicgationconreoller it was crashing, I fixed that somehow...

how can I create a button with texturepackerimporter texture?


unity3d,uibutton,texturepacker
I can drag the prefabs texture to scene. But I don't know how to create a ui button use this texture.

Simulator not found in Product->destination (Xcode) [Solved]


ios,objective-c,xcode,git,ios7
I download a project from github git clone https://github.com/alienjun/CITwirlDistortionDemo.git When I try running it , I find that there aren't any simulators in the Product->destination I can use the simulator if I create a new project( single view ) why I can't find simulator when I use this project cloned...

iOS How to manage different features that requires a 3rd-party framework


ios,ios7,ios-frameworks
I developed an SDK distributed to our publishers as a standard iOS framework. To be as much clear as possibile let's say my SDK is called 'A'. 'A' needs a 3rd-party iOS framework (called 'B') that manages a particular feature. So, for example, I have a class in 'A' like...

Add a 0.5 point height subview to UINavigationBar not show in iOS7


ios,objective-c,ios7,uiview,uinavigationbar
I have a class inherit from UINavigationBar and I want to add a separator line as its subview to separate the navigation bar and the navigation content. The line's height is defined as following. #define SEPERATOR_LINE_HEIGHT (1.0f / [UIScreen mainScreen].scale) My code: @interface MyPopNavigationBar : UINavigationBar @end @implementation MyPopNavigationBar {...

Prevent user from entering more characters into uitextview


ios7,xcode6,uitextview,edit
How could I prevent the user from entering any more characters into a uitextview after the textview has reached a given height? Here is the code I thought would work but does not. I can't put in any more characters but for some reason I can't even delete any.. -...

Multiple Buttons, But only one pressed at a time


ios,objective-c,uibutton
I've been looking through the site and I've been unable to find anything that answers my question. In my app i have a modal dialog that displays a UICollectionView that uses a custom cell and only contains a UIButton. I have set the buttons up to be selectable rather than...

How can i call the method from class Method [duplicate]


ios,iphone,ios7,ios5
This question already has an answer here: Call instance method from class method 3 answers i want to call the method [self methodName]; in class method but it will not call in same class. i tried +(void)myMehod { [self methoName]; } ...

Check UITextfield have only Alphabet not numeric value


ios,iphone,ios7
I am creating one form I want to check in Name Field if any one enter Number then show alert. Here is the code: NSString *str = abc.text; NSCharacterSet *alphaSet = [NSCharacterSet alphanumericCharacterSet]; BOOL valid = [[str stringByTrimmingCharactersInSet:alphaSet] isEqualToString:@""]; if (!(valid)) { NSLog(@"number present"); } else { NSLog(@"number not present");...

Update button image on swift 2.0


ios,uibutton,swift2,xcode7
When I try using this solution to update an UIButton image (Xcode 7 beta 1), it gives me this error: "Cannot invoke 'setImage' with an argument list of type '(UIImage?, forState: nil)'" Here's the code: if counter % 2 == 0{ playButton.setImage(UIImage(named: "pause"), forState: nil) } else if counter %...

Splash screen not visible for iPad, only a black screen gets shown


ios,ios7
I have an universal app. The splash screen loads fine for iPhone but the same is not visible on the iPad. Instead a black screen appears in its place. I have gone through the questions posted in this regard and have followed the steps but to no avail. I am...

How can I create this Switch behavior?


ios,uibutton,uistoryboard,uiswitch
I want to create the following selection button to pick from the two options "Salary" and "Hourly Wage". I have images for when either (left or right) option are selected. What UI element in iOS can I use to create this? Looked into a Switch but did not see an...

Setting layer out of layer in UIbutton?


ios,objective-c,uibutton,uiimage,calayer
i want this type of button i have tried pictureBtn which is UIbutton ,i gave it a 5 pixel clear color corner radius and add a picture like camera below but last outer white line how to deal with this can anybody have ideas or something like control. ...

Set bool for UIButton Class in View controller (Swift)


ios,swift,uibutton
I have a Custom Class for my UIButton. In this class I have the code below to draw the button. I would like the user to tap a button and toggle one part hidden/ not hidden. I don't know how to set the Bool value for this. Thanks import UIKit...

Using tags in Swift


ios,swift,uibutton,tags
I have about 15 UIButtons in my controller. Im trying to clear 10 of them with a simple for loop and looks like I am getting some kind of conflict. When I hit the button to clear, I get the following error: Could not cast value of type '_UISizeTrackingView' (0x18a023c)...

Showing leaderboard crashes app because showViewController isn't supported


ios,swift,ios7,ios8,game-center-leaderboard
What is the right way to present Game Center leaderboards in iOS 7? The code below crashes on showViewController because it only supports iOS 8. Other Stack Overflow posts suggest using presentViewController for iOS 7, but that only shows a blank leaderboard. func showLeaderboards() { // User logged into GameCenter?...

How do I toggle hidden of a label while a button is pressed?


ios,uibutton,uikit,uilabel
I am trying to figure out how to only display a label while a button is pressed in OS. I know how to operate the touch events but I am not sure how to incorporate the UILongPressGestureRecognizer into this.

Presenting a view controller triggers UIApplicationDidChangeStatusBarOrientationNotification


ios,objective-c,iphone,ios7,ios8
I've got a universal app that supports both iPad and iPhone, and on the iPhone it supports UIInterfaceOrientationPortraitUpsideDown. When I run the app on an iPhone, then rotate the device to UIInterfaceOrientationPortraitUpsideDown, then modally present a view controller like this: UIViewController* vc = [[UIViewController alloc] initWithNibName:nil bundle:nil]; UINavigationController* navigationController =...

first tap not registering on collectionView Xcode


objective-c,xcode,ios7,uiviewcontroller,collectionview
I have a collectionView with an array populating it. I have it set up that when a cell is tapped a second modal view is presented. The problem is that the first tap is not recognized. The collectionView in storyboard, along with the cell and the image inside the cell...

how can I create a URL/site to send a HTTP 204 or HTTP 403 response?


objective-c,http,servlets,post,ios7
I'm trying to create an app with a login page to POST to a url and return a status code. For now the app is to call a URL that returns a HTTP 204 or HTTP 403 response. How is this done? Do I need to create/implement a servlet?

Autolayout works great on iOS 8, crashes on iOS 7


ios,ios7,ios8,autolayout
I have an issue where a screen with autolayout that works great on iOS 8 - but crashes on iOS 7. All subviews are configured in the XIB. The error message is: Terminating app due to uncaught exception 'NSGenericException', reason: 'Unable to install constraint on view. Does the constraint reference...

Will handling UIButton touch event inside a UITableViewCell subclass violate MVC?


ios,objective-c,uitableview,model-view-controller,uibutton
There is a UITableViewCell subclass with a UIButton inside. A web call should be made when the button is pressed. The question is whether I should set the action in the controller, or can the action be set within the UITableViewCell subclass? Will the second option violate MVC pattern?...