iPhone/iPad UIButton TitleLabel text not appearing
I think you want setTitle: forState: [button setTitle:@”Baha’i” forState:UIControlStateNormal]
I think you want setTitle: forState: [button setTitle:@”Baha’i” forState:UIControlStateNormal]
I was looking for a solution and DotSlashSlash has the answer hidden in one of the comments! For the sake of completeness, the answer and the simplest solution is: UIImage *myGradient = [UIImage imageNamed:@”textGradient.png”]; myLabel.textColor = [UIColor colorWithPatternImage:myGradient];
Based in @krunal answer, this is working for me: extension UIViewController { func setupNavigationMultilineTitle() { guard let navigationBar = self.navigationController?.navigationBar else { return } for sview in navigationBar.subviews { for ssview in sview.subviews { guard let label = ssview as? UILabel else { break } if label.text == self.title { label.numberOfLines = 0 label.lineBreakMode = … Read more
If you want to make sure the label fits in the rectangle both width and height wise you can try different font size on the label to see if one will fit. This snippet starts at 300 pt and tries to fit the label in the targeted rectangle by reducing the font size. – (void) … Read more
This is now available in UIFont since iOS 9: + (UIFont *)monospacedDigitSystemFontOfSize:(CGFloat)fontSize weight:(CGFloat)weight NS_AVAILABLE_IOS(9_0); eg: [UIFont monospacedDigitSystemFontOfSize:42.0 weight:UIFontWeightMedium]; or in Swift: UIFont.monospacedDigitSystemFont(ofSize: 42.0, weight: UIFontWeightMedium)
#swift 4.2 Please find the solution here for getting specific text action of Label. Label declaration @IBOutlet weak var lblTerms: UILabel! Set attributed text to the label let text = “Please agree for Terms & Conditions.” lblTerms.text = text self.lblTerms.textColor = UIColor.white let underlineAttriString = NSMutableAttributedString(string: text) let range1 = (text as NSString).range(of: “Terms & … Read more
NSRangeException Out of Bounds error
The question was already answered for the OP, but for the sake of other people who come here trying to change a label’s text color, use the textColor property: Swift myLabel.textColor = UIColor.red // or .red Objective-C myLabel.textColor = [UIColor redColor];
From iOS 6 you can use NSAttributedString in UILabel. In attributed string you can use attribute NSKernAttributeName to set letter spacing NSMutableAttributedString* attrStr = [[NSMutableAttributedString alloc] initWithString: @”Test test test test “]; [attrStr addAttribute:NSKernAttributeName value:@(4.0) range:NSMakeRange(0, attrStr.length)]; UILabel* label = [[UILabel alloc] initWithFrame:CGRectMake(0, 300, 300, 100)]; label.attributedText = attrStr;
I think you just need to add this: label.adjustsFontSizeToFitWidth = YES; label.minimumFontSize = 0; Then the text will automatically resize to fit the label. Note however that this will only really work if the label.numberOfLines = 1, so that the text is on a single line. If you need the text to wrap onto multiple … Read more