uilabel

How to figure out the font size of a UILabel when -adjustsFontSizeToFitWidth is set to YES?

老子叫甜甜 提交于 2019-12-17 07:24:21
问题 When myLabel.adjustsFontSizeToFitWidth = YES , UILabel will adjust the font size automatically in case the text is too long for the label. For example, if my label is just 100px wide, and my text is too long to fit with the current font size, it will shrink down the font size until the text fits into the label. I need to get the actual displayed font size from UILabel when the font size got shrunk down. For example, let's say my font size was actually 20, but UILabel had to shrink it down to

How to set kerning in iPhone UILabel

允我心安 提交于 2019-12-17 07:14:23
问题 I am developing an iPhone app, and I want to set kerning in UILabel. The code I've written (possibly around kCTKernAttributeName ) seems to be in error. How might I approach fixing this? NSMutableAttributedString *attStr; NSString *str = @"aaaaaaa"; CFStringRef kern = kCTKernAttributeName; NSNumber *num = [NSNumber numberWithFloat: 2.0f]; NSDictionary *attributesDict = [NSDictionary dictionaryWithObject:num forKey:(NSString*)kern]; [attStr initWithString:str attributes:attributesDict]; CGRect

How can you rotate text for UIButton and UILabel in Swift?

风流意气都作罢 提交于 2019-12-17 04:51:13
问题 How can you rotate text for UIButton and UILabel ? 90 degrees, 180 degrees. Note: Before you mark this as a duplicate, I am intentionally modelling my question as a Swift version of this one: How can you rotate text for UIButton and UILabel in Objective-C? 回答1: I am putting my answer in a similar format to this answer. Here is the original label: Rotate 90 degrees clockwise: yourLabelName.transform = CGAffineTransform(rotationAngle: CGFloat.pi / 2) Rotate 180 degrees: yourLabelName.transform

How can you rotate text for UIButton and UILabel in Swift?

对着背影说爱祢 提交于 2019-12-17 04:48:50
问题 How can you rotate text for UIButton and UILabel ? 90 degrees, 180 degrees. Note: Before you mark this as a duplicate, I am intentionally modelling my question as a Swift version of this one: How can you rotate text for UIButton and UILabel in Objective-C? 回答1: I am putting my answer in a similar format to this answer. Here is the original label: Rotate 90 degrees clockwise: yourLabelName.transform = CGAffineTransform(rotationAngle: CGFloat.pi / 2) Rotate 180 degrees: yourLabelName.transform

How do I set bold and italic on UILabel of iPhone/iPad?

自闭症网瘾萝莉.ら 提交于 2019-12-17 04:16:30
问题 How do I set bold and italic on UILabel of iPhone/iPad? I searched the forum but nothing helped me. Could anyone help me? 回答1: sectionLabel.font = [UIFont fontWithName:@"TrebuchetMS-Bold" size:18]; There is a list of font names that you can set in place of 'fontWithName' attribute.The link is here 回答2: Don't try to play with the font names. Using the font descriptor you need no names: UILabel * label = [[UILabel alloc] init]; // use your label object instead of this UIFontDescriptor * fontD =

How do I create a round cornered UILabel on the iPhone?

一曲冷凌霜 提交于 2019-12-17 04:12:11
问题 Is there a built in way to create round-cornered UILabels? If the answer is no, how would one go about creating such an object? 回答1: iOS 3.0 and later iPhone OS 3.0 and later supports the cornerRadius property on the CALayer class. Every view has a CALayer instance that you can manipulate. This means you can get rounded corners in one line: view.layer.cornerRadius = 8; You will need to #import <QuartzCore/QuartzCore.h> and link to the QuartzCore framework to get access to CALayer's headers

UILabel layer cornerRadius negatively impacting performance

流过昼夜 提交于 2019-12-17 04:11:58
问题 I've created a document view which displays the page number in the corner. The page number is a uilabel with a semi-transparent background colour, and has a corner radius (using the cornerRadius property of the view 's layer ). I've positioned this above a UIScrollView . However, this makes scrolling jerky. If I remove the cornerRadius , performance is good. Is there anything I can do about this? What would be a better solution? It seems to have been achieved in the UIWebView without any

How to control the line spacing in UILabel

爷,独闯天下 提交于 2019-12-17 03:21:45
问题 Is it possible to reduce the gap between text when put in multiple lines in a UILabel ? We can set the frame, font size and # of lines. I want to reduce the gap between the two lines in that label. 回答1: I thought about adding something new to this answer, so I don't feel as bad... Here is a Swift answer: import Cocoa let paragraphStyle = NSMutableParagraphStyle() paragraphStyle.lineSpacing = 40 let attrString = NSMutableAttributedString(string: "Swift Answer") attrString.addAttribute(

Adjust UILabel height to text

核能气质少年 提交于 2019-12-17 02:33:43
问题 I have some labels which I want to adjust their height to the text, this is the code I wrote for this now func heightForView(text:String, font:UIFont, width:CGFloat) -> CGFloat{ let label:UILabel = UILabel(frame: CGRectMake(0, 0, width, CGFloat.max)) label.numberOfLines = 0 label.lineBreakMode = NSLineBreakMode.ByWordWrapping label.font = font label.text = text label.sizeToFit() return label.frame.height } EDIT: The issue was not in this piece of code, so my fix is in the question itself. It

iPhone - UILabel containing text with multiple fonts at the same time

▼魔方 西西 提交于 2019-12-17 01:02:57
问题 I am looking for a way to use a UILabel (or something similar) to display something like this: Tom: Some message. It is like how it's done in for example the Facebook app to display the "what's on your mind?" messages. Does anyone have any suggestions how to approach this? 回答1: Use two UILabel IBOutlets, each with a different format (font/color/etc), as you desire.. Move the second one over the first based on where the first one's text ends. You can get that via sizeWithFont:forWidth