uilabel

Get an Int out of an UILabel Swift

ぐ巨炮叔叔 提交于 2019-12-20 02:47:05
问题 I have the problem, to have a high amount of buttons which have a number as their label, so i thought i could take the label as an integer instead of creating an action for every button?! @IBAction func NumberInput(sender: UIButton) { var input:Int = sender.titleLabel as Int } 回答1: If you want to do this, you can convert the string to an Int by using string.toInt() such as: if let input = sender.titleLabel?.text?.toInt() { // do something with input } else { // The label couldn't be parsed

AutoLayout constraints to UITableViewCell contentView not respected

和自甴很熟 提交于 2019-12-20 02:13:29
问题 I'm trying to create dynamically resizing table view cells. I accomplished the resizing by using this answer, which is very detailed and helpful. However, the maximum width for the label is not being calculated correctly in heightForRowAtIndexPath . My cell currently only has one label in its contentView , with constraints set to pin all the label edges to the contentView edges. Here's what I have in IB The cell size is being calculated with an offscreen cell in heightForRowAtIndexPath using

AutoLayout constraints to UITableViewCell contentView not respected

五迷三道 提交于 2019-12-20 02:13:08
问题 I'm trying to create dynamically resizing table view cells. I accomplished the resizing by using this answer, which is very detailed and helpful. However, the maximum width for the label is not being calculated correctly in heightForRowAtIndexPath . My cell currently only has one label in its contentView , with constraints set to pin all the label edges to the contentView edges. Here's what I have in IB The cell size is being calculated with an offscreen cell in heightForRowAtIndexPath using

Best way to strike out a text

天大地大妈咪最大 提交于 2019-12-20 01:47:19
问题 What is the best solution so far for a strike out text on the iPhone? I heard of multiple solutions: Something with three20 Image as a subview UIWebView And something with a NSAttributedString , but I don't find a working example for that. 回答1: In iOS 6 we can use "NSMutableAttributedString" for use more different styles. NSString* cutText = @"This Line is strike out."; NSMutableAttributedString *titleString = [[NSMutableAttributedString alloc] initWithString:cutText]; // making text property

Is it possible to assign an accessibility action to a UILabel?

时光毁灭记忆、已成空白 提交于 2019-12-19 19:56:15
问题 In our current UI, next to certain labels, we have a help-tip button that when clicked, explains the details of what the label references. As such, VoiceOver identifies these two items as separate accessibility items. However, when using accessibility, we're hoping we can just do everything in the label itself. This way when the label gets focused, the user will here 'Account value, $20 (the accessibilityLabel), double-tap for help (the accessibilityHint)' However, unlike a button, a label

Get Width of last line of multiline UILabel

↘锁芯ラ 提交于 2019-12-19 18:22:49
问题 I have a dynamic multi line UILabel and need to know the end of the text (X Coordinate) of the visible text (not the Label) so I can show something after the text. Is this possible? thank you 回答1: You'll be able to have more control over the text layout with the CoreText framework. Checkout the documentation: There are also some nice open source things that already do a lot of the hard work for you, like: https://github.com/Cocoanetics/DTCoreText 回答2: As far as I know , the best solution for

Get Width of last line of multiline UILabel

老子叫甜甜 提交于 2019-12-19 18:18:29
问题 I have a dynamic multi line UILabel and need to know the end of the text (X Coordinate) of the visible text (not the Label) so I can show something after the text. Is this possible? thank you 回答1: You'll be able to have more control over the text layout with the CoreText framework. Checkout the documentation: There are also some nice open source things that already do a lot of the hard work for you, like: https://github.com/Cocoanetics/DTCoreText 回答2: As far as I know , the best solution for

System font “Hiragino Sans” is show with clipped ascender and descenders

非 Y 不嫁゛ 提交于 2019-12-19 11:36:12
问题 I need to use the iOS's system font "Hiragino Sans W3" in my app, but no matter which size/style or the UILabel 's dimensions I choose, the font's ascenders and descenders always appear clipped: It seems that this can this fixed by creating a subclass of UILabel and overwriting method textRectForBounds:limitedToNumberOfLines: to return the "correct" value. So the following code... - (CGRect)textRectForBounds:(CGRect)bounds limitedToNumberOfLines:(NSInteger)numberOfLines { CGRect result =

How to change font size for iPhone 4 and IPhone 5 in auto-layout?

杀马特。学长 韩版系。学妹 提交于 2019-12-19 11:24:38
问题 I am trying to change font size of uilabel for iphone 4 and iphone 5 using autolayout and size classes. IB is giving option only for ipad and greater phones like iphone 6 and 6P . If i change font for wR and hR then it changes fonts size for iphone 4 , 5 and 6 which is wrong in my case . Please help me in this regard. 回答1: Unfortunately , Apple Provides minimum consideration for all iPhone's(4,5,6,6p version) Portrait Mode Compact Width - Compact Height or Compact Width - Regular Height . So

Calling method sizeToFit on a UILabel that has subscripts is not working

耗尽温柔 提交于 2019-12-19 07:51:17
问题 I have a subclass of UILabel, which is supposed to update its text when the user types something. Naturally, as the length of text increases, the size of the label must adjust to accommodate the text. I called the sizeToFit method, and while the label adjusts its width correctly, the bottom of the text is cut off. The problem is that the text includes subscripts and superscripts , and the label is not adjusting itself with the subscripts in consideration (for example, with H₂O the bottom of