uilabel

Change the height of UILabel dynamically based on content

北战南征 提交于 2019-12-17 16:31:48
问题 I have a UILabel as subview of UIButton and I am passing the value from another view and populating in UILabel . Now, I want that UILabel must change its height based on the content.If text is "Hello" it must be in 1 line but if text is " my text is too long to fit in the label", it must change its size. I have used [self.addressLabel sizeToFit]; But for this i need to leave empty space below UILabel. Simply what I want is that when text strength increases,size of UILabel and UIView must

add hyphens on word break in a UILabel

做~自己de王妃 提交于 2019-12-17 15:44:31
问题 How do I set a UILabel lineBreakMode to break words and add hyphens to broken words? a label with a broken wo- rd should look like this 回答1: Elaborating on Matt's answer here: https://stackoverflow.com/a/16502598/196358 it can be done using NSAttributedString and NSParagraphStyle. See below: NSMutableParagraphStyle *paragraphStyle = [[NSMutableParagraphStyle alloc] init]; paragraphStyle.hyphenationFactor = 1.0f; NSMutableAttributedString *attributedString = [[NSMutableAttributedString alloc]

How to set multi line Large title in navigation bar? ( New feature of iOS 11)

╄→гoц情女王★ 提交于 2019-12-17 15:39:33
问题 I am in process of adding large title in navigation bar in one of the application. The issue is title is little long so I will require to add two lines in large title. How can I add large title with two lines in navigation bar ? This is not about default navigation bar title ! This is about large title which is introduced in iOS 11 . So make sure you add suggestions by considering large title. Thanks 回答1: Based in @krunal answer, this is working for me: extension UIViewController { func

Decrease the width of the last line in multiline UILabel

不羁的心 提交于 2019-12-17 15:29:12
问题 I am implemententing a "read more" functionality much like the one in Apple's AppStore. However, I am using a multiline UILabel . Looking at Apple's AppStore, how do they decrease the last visible line's width to fit the "more" text and still truncate the tail (see image)? 回答1: This seems to work, at least with the limited amount of testing I've done. There are two public methods. You can use the shorter one if you have multiple labels all with the same number of lines -- just change the

Adding a CGGradient as sublayer to UILabel hides the text of label

血红的双手。 提交于 2019-12-17 13:45:16
问题 I want to add the gradient as a background to label. I used the following code to acheive that. but the problem is that though the gradient color appears on the label, but the text is not visible. please help lblPatientDetail.text=PatientsDetails; lblPatientDetail.textColor=[UIColor blackColor]; CAGradientLayer *gradient = [CAGradientLayer layer]; gradient.frame = lblPatientDetail.bounds; gradient.colors = [NSArray arrayWithObjects:(id)[[UIColor whiteColor] CGColor],(id)[[UIColor colorWithRed

Getting UILabel to produce an ellipsis rather than shrinking the font

被刻印的时光 ゝ 提交于 2019-12-17 10:54:02
问题 When I dynamically change the text of a UILabel I would prefer to get an ellipsis (dot, dot, dot) rather then have the text be automatically resized. How does one do this? In other words, if I have UILabel with the word Cat with size font 14 and then I change the word to Hippopotamus the font shrinks to fit all the word. I would rather the word be automatically truncated followed by an ellipsis. I assume there is a parameter that can be changed within my UILabel object. I'd rather not do this

update label from background timer

社会主义新天地 提交于 2019-12-17 10:06:53
问题 Good Day, I am developing a workout app that works fine except when moving it to the background. The timer suspends when it does. I found an example of a background timer that I have working but now I can't get the UILabel that displays the duration of the workout to work. In the console it states that I am accessing an object from the main thread which I understand. What I don't know how to do is to get the UILabel to update as the timer updates from within the background thread with the

iOS Add left padding to UILabel

╄→尐↘猪︶ㄣ 提交于 2019-12-17 08:29:25
问题 I need to create a UILabel with a background color, and I'd like to add some left padding but every solution I've found around here seems like a nasty hack. Which is the 'standard' way to achieve this from iOS 5 ahead? EDIT A screenshot to illustrate my scenario.- 回答1: For a full list of available solutions, see this answer: UILabel text margin Try subclassing UILabel, like @Tommy Herbert suggests in the answer to [this question][1]. Copied and pasted for your convenience: I solved this by

Center NSTextAttachment image next to single line UILabel

我是研究僧i 提交于 2019-12-17 08:01:41
问题 I'd like to append an NSTextAttachment image to my attributed string and have it centered vertically. I've used the following code to create my string NSMutableAttributedString *str = [[NSMutableAttributedString alloc] initWithString:DDLocalizedString(@"title.upcomingHotspots") attributes:attrs]; NSTextAttachment *attachment = [[NSTextAttachment alloc] init]; attachment.image = [[UIImage imageNamed:@"help.png"] imageScaledToFitSize:CGSizeMake(14.f, 14.f)]; cell.textLabel.attributedText = [str

uilabel tail truncation

血红的双手。 提交于 2019-12-17 07:52:12
问题 Im working on an ios app using objective c and i have an issue with uilabel that i could use some help with. Basically i have a label that can change size to fit the text that it will display but it has a max height that it can possible be. the label itself has a fixed width at all times. i have turned on UILineBreakModeWordWrap and UILineBreakModeTailTruncation to make the text fit and truncate but this causes the text to truncate the tail too early when it has only 1 word left to place.