uilabel

UITableView comes to a crawl when adding a UILabel with cornerRadius to each cell

大城市里の小女人 提交于 2019-12-29 05:25:13
问题 I'm adding a UILabel to each cell in my table view. This presents no problem initially. When I round the corners of the UILabel using layer.cornerRadius scrolling the table view grinds to a halt. UILabel *label1 = [[UILabel alloc] initWithFrame:CGRectMake(cell.bounds.origin.x+10 ,5, 30, 30)]; label1.backgroundColor = ([[managedObject valueForKey:@"color"] hasPrefix:@"FFFFFF"]) ? [UIColor blackColor] : color; label1.layer.cornerRadius = 10.0f; [cell addSubview:label1]; 回答1: I've tried this

iPhone UILabel - non breaking space

守給你的承諾、 提交于 2019-12-28 16:31:58
问题 Is there a way to use non breaking spaces in UILabel text? For example, I have label with 2 lines and line breaking mode set to word wrap. The content for this label is read from database, where it's stored as a string. Now sometimes my text in label looks like that: lorem ipsum some text 1 but I want to display it like that: lorem ipsum some text 1 so basicly, I need to force non breaking space between 'text' and '1'. I've found some solution here, but I think it could work when the text is

iOS - Draw gradient - Swift

左心房为你撑大大i 提交于 2019-12-28 16:27:20
问题 I'm trying to draw a gradient to UILabel, but it draws only the colors I can't see the text. I saw the code from here StackOverflow my modification: extension String{ func gradient(x:CGFloat,y:CGFloat, fontSize:CGFloat)->UIImage{ let font:UIFont = UIFont.systemFontOfSize(fontSize) let name:String = NSFontAttributeName let textSize: CGSize = self.sizeWithAttributes([name:font]) let width:CGFloat = textSize.width // max 1024 due to Core Graphics limitations let height:CGFloat = textSize.height

Dynamically resize label in iOS 7

蓝咒 提交于 2019-12-28 13:40:24
问题 In iOS 6, I am using : CGSize labelSize = [self.text sizeWithFont:self.font constrainedToSize:size lineBreakMode:self.lineBreakMode]; self.frame = CGRectMake(self.frame.origin.x, self.frame.origin.y , labelSize.width, self.frame.size.height); To dynamically resize a UILabel. This does not work in iOS 7 so I tried: NSString *text = self.text; CGFloat width = size.width; UIFont *font = self.font; NSAttributedString *attributedText = [[NSAttributedString alloc] initWithString:text attributes:@{

UILabel: background dependent color

一个人想着一个人 提交于 2019-12-28 12:16:28
问题 I have tried to search for solutions for this problem, but I am not even able to put it correctly in words I guess. Basically I have a bar that gets filled up with a color while an operation proceeds. I have a label with the progress percentage that has the same color has the fill color, so I need it to change when the fill color is on the back. Something like this: Is it possible in anyway to achieve this result? And in case, how? 回答1: The easiest way is to create a UIView subclass that has

UILabel: background dependent color

断了今生、忘了曾经 提交于 2019-12-28 12:15:13
问题 I have tried to search for solutions for this problem, but I am not even able to put it correctly in words I guess. Basically I have a bar that gets filled up with a color while an operation proceeds. I have a label with the progress percentage that has the same color has the fill color, so I need it to change when the fill color is on the back. Something like this: Is it possible in anyway to achieve this result? And in case, how? 回答1: The easiest way is to create a UIView subclass that has

UILabel touch and get the text where touched

时光总嘲笑我的痴心妄想 提交于 2019-12-28 11:56:10
问题 I've UILabel which has some text and 2 month names like "In the month of January and July, sun shine will be peak" I sub classed UILabel and added touch event to it. Now I want to get the word below the text where user touched and find out whether user touched January/July or not. Is it possible? 回答1: I think you'll find what you're looking for in the documentation for UITextInputProtocol. For some more high level information, check out Apple's Text, Web and Editing Guide, specifically in the

How to Increase Line spacing in UILabel in Swift

你说的曾经没有我的故事 提交于 2019-12-28 04:54:06
问题 I have a label which has few lines of text and I want to increase the spacing between the lines. There are similar questions asked by others but the solutions don't solve my problems. Also my label may or may not contain paragraphs. I am new to Swift . Is there a solution using storyboard? Or only through NSAttributedString its possible? 回答1: Programatically add LineSpacing to your UILabel using following snippet. Earlier Swift version let attributedString = NSMutableAttributedString(string:

How to underline a UILabel in swift?

心已入冬 提交于 2019-12-28 03:31:05
问题 How to underline a UILabel in Swift? I searched the Objective-C ones but couldn't quite get them to work in Swift. 回答1: You can do this using NSAttributedString Example: let underlineAttribute = [NSUnderlineStyleAttributeName: NSUnderlineStyle.StyleSingle.rawValue] let underlineAttributedString = NSAttributedString(string: "StringWithUnderLine", attributes: underlineAttribute) myLabel.attributedText = underlineAttributedString EDIT To have the same attributes for all texts of one UILabel, I

Animate UILabel text between two numbers?

…衆ロ難τιáo~ 提交于 2019-12-27 18:23:07
问题 I'm new to iPhone and Mac programming (developed for Windows before), and I've got a question: How do I animate the text property of an UILabel between two numbers, e.g. from 5 to 80 in an Ease-Out style? Is it possible with CoreAnimation ? I have been searching on Google for an hour, but I haven't found anything solving my problem. What I want: Animate the users money for a simple game. It doesn't look very nice when it just goes from 50 to 100 or something like that without animation.