uilabel

UILabel text to fill in the frame width

好久不见. 提交于 2019-12-22 08:36:14
问题 I want to build typography poster using UILabel left and margin: 25 320(device width) - 50(sum of the margins) = 270(label width frame) The font size of each label should change in order to fit in 270 frame width I try with sizeToFit() , adjustsFontSizeToFitWidth=true var margin = 0; let label = UILabel(frame: CGRectMake(25 , 72, 270, 70)); label.backgroundColor = UIColor.clearColor(); label.textAlignment = NSTextAlignment.Left; label.textColor = UIColor.blackColor(); label.numberOfLines = 1;

detect urls in UILabel

一个人想着一个人 提交于 2019-12-22 06:45:41
问题 I have a Tableview and tableview cell is customized to have a UILabel. The text in UILabel is having URLs. Is there a way to detect urls like how UITextView will enable detect URLs so that user interaction should be able to load the urls. 回答1: If you just want to identify the URLs, you can use NSDataDetector with the NSTextCheckingTypeLink checking type. If you want to draw the URLs differently, and you are targeting iOS 6, you can use an NSAttributedString to turn the URLs blue or underline

Resizing the height of UILabel to fit text

拜拜、爱过 提交于 2019-12-22 05:13:54
问题 I have UILabel in my Cell Subclass which is suppose to hold a title. The size of the title can be various lengths and therefor I need to resize the UILabel to fit the text and to prevent that the text is not to long I also need to be able to set maxHeight. The width should be the same. How can I create such code in swift in a tableViewCell subclass? So far I have this in awakeFromNib theTitleLabel?.font = UIFont(name: "HelveticaNeue", size: 13) theTitleLabel?.textColor = UIColor(rgba: "

Xcode: Is there a way to change line spacing (UI Label) in interface builder?

故事扮演 提交于 2019-12-22 05:00:32
问题 I've got several UILabels with multiple lines of text, but the line spacing is larger than I would prefer. Is there any way to change this? 回答1: Since iOS 6, Apple added NSAttributedString to UIKit , making it possible to use NSParagraphStyle to change the line spacing. To actually change it from NIB, please see souvickcse's answer. 回答2: hi this is a late reply but it may help some one line height can be change change the text from plain to attribute 回答3: Because I friggin hate using

CATextLayer wrapped sizeToFit?

六月ゝ 毕业季﹏ 提交于 2019-12-22 04:17:09
问题 If I set textLayer.wrapped = YES , how do I resize textLayer to contain the wrapped text? I.e., how do I get the new height of the textLayer ? Basically, I want something like -[UILabel sizeToFit] . 回答1: The first thing you need to do is get the size of the text. Thankfully, the NSString UIKit Additions Reference offers a method to do exactly that: - (CGSize)sizeWithFont:(UIFont *)font constrainedToSize:(CGSize)size lineBreakMode:(UILineBreakMode)lineBreakMode That will give you a CGSize that

Change UILabel's textColor in whole app using Swift

你。 提交于 2019-12-22 04:16:36
问题 Is there any way in Swift i can change my UILabel's text color property at once in whole app? I've tried using appeareance property but that doesn't work for UILabel textColor. Any way or any library that works on the same. 回答1: One way is using Color Set . Start with creating new set in your xcassets catalog ... and name it how you want to Then change your color to color that you need Finally, set color of your label as this color from xcassets catalog ... or programmatically label.textColor

UILabel text property when set to nil or “” makes UILabel disappear from view (Swift / Autolayout/ iOS9.1)

ε祈祈猫儿з 提交于 2019-12-22 04:15:10
问题 I am going through the Stanford Winter 2015 Swift/iOS course and while doing the assignments I run into a behavior I'd like to change. I use Autolayout as described in the videos (making the display pin to leading and trailing view edges) and the Calculator app "Display" UILabel is fine with an initial value of 0 and whenever the value used to set it (a String) is non-nil and non "". If it is either nil or "", the entire UILabel disappears. What I am trying to do is to "clear" the display

How to 'addTarget' to UILabel in Swift

心不动则不痛 提交于 2019-12-22 04:11:11
问题 I am trying to add labels in Swift, which are added in a loop. I then want to add a 'TapGesture' event to each one as they are added. It works , but the problem is that the function called takes data from the label to use when it's clicked, but the label has been redefined by then and it takes data from the last one added, not the one that was clicked. How can I make each one unique? self.label.attributedText = self.myMutableString let tapGesture = UITapGestureRecognizer(target: self, action:

How to 'addTarget' to UILabel in Swift

馋奶兔 提交于 2019-12-22 04:11:01
问题 I am trying to add labels in Swift, which are added in a loop. I then want to add a 'TapGesture' event to each one as they are added. It works , but the problem is that the function called takes data from the label to use when it's clicked, but the label has been redefined by then and it takes data from the last one added, not the one that was clicked. How can I make each one unique? self.label.attributedText = self.myMutableString let tapGesture = UITapGestureRecognizer(target: self, action:

Adding TapGestureRecognizer to UILabel in Swift

青春壹個敷衍的年華 提交于 2019-12-22 03:58:07
问题 I add a UITapGestureRecognizer:tapGesture , I want that when I click(touch) the label, klikPlay() will run its actions. when I run the code and click/touch the label, it gives this error: unrecognized selector sent to instance. It is about the label Player(named: label) , the UITapGestureRecognizer(named:tapGesture) and the function klikPlay What am I doing wrong? override func didMoveToView(view: SKView) { let background = SKSpriteNode(imageNamed: "bgStart2") background.position = CGPoint(x