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


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 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 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];



You need to use this line to set attributed title

[calendarBtn setAttributedTitle: ddStr forState:UIControlStateNormal];

instead of


Hope it helps :)


Setting layer out of layer in UIbutton?

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. ...

Remove “heightForRowAtIndexPath” for iOS8

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...

Using tags in Swift

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)...

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

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.

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

I have to add directions among two custom locations in IOS 7. Any one tell me please. Thanks. ...

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

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...

Check UITextfield have only Alphabet not numeric value

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");...

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

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...

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

I download a project from github git clone 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...

Swift: Set UIButton Image with CGRect

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...

first tap not registering on collectionView Xcode

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...

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

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...

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

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:)])...

Changing titles on buttons with custom NSString

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",...

Draw attention to and foster discovery of actionable controls

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....

How can I create this Switch behavior?

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...

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

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 {...

UIButton creating error - “unrecognized selector sent to instance”

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",...

Multiple Buttons, But only one pressed at a time

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...

Prevent user from entering more characters into uitextview

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.. -...

Set custom attribute on button

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...

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

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 : self.buttonShrink = [CAKeyframeAnimation animationWithKeyPath:@"transform"]; self.buttonShrink.duration = .2f; self.buttonShrink.values...

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

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 to change image of UIImageView that is inside a UIButton programatically?

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 can I create a URL/site to send a HTTP 204 or HTTP 403 response?

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?

UIButton Text Only Appearing On Touch

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) = CGRectGetMidX(self.view.bounds)...

Swift - How to properly architect buttons in MVC?

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...

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

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]; } ...

How to dynamically add an action to a 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)...

Custom UIButton Swift 2.0

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...

What does this auto layout error mean?

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...

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

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?...

Unwanted Invisible detection area around UIButton when Highlighted

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...

Checking UIButton Image

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"]]...

UIButton with pushViewController that is declared in another class

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...

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

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...

Update button image on swift 2.0

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

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...

Simple animation not working on iOS7

Im using a button to trigger the following animation: newPosition1=CGPointMake(200.0f + _btnAgregar.frame.size.width/2.0f,; [UIView animateWithDuration:0.5f animations:^{; }]; 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]

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!)...

Swift - UIButton with two lines of text

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...

how can I create a button with texturepackerimporter texture?

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

Showing leaderboard crashes app because showViewController isn't supported

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?...

Autolayout works great on iOS 8, crashes on iOS 7

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...

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

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 bool for UIButton Class in View controller (Swift)

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...

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

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...

Presenting a view controller triggers UIApplicationDidChangeStatusBarOrientationNotification

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 =...

Calling prepareforSegue from a UIButton?

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:...

UIButton with single press and long press events swift

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...