uilabel

iphone : sizeWithFont method does not identify the '\n' from string

孤人 提交于 2019-12-07 05:41:43
问题 I am using below code to calculate the size for the label for a string. NSString * str = @"It's \n that \n don't \n"; CGSize size = [str sizeWithFont:[UIFont fontWithName:@"Verdana" size:12.5] forWidth:300 lineBreakMode:UILineBreakModeWordWrap]; NSLog(@"Height : %f Width : %f ",size.height,size.width); But id does not consider \n characters from the string to change the line. When I display this string on a label and set it numberOfLines property to some 4 or 5 , label does consider the \n

iOS FontAwesome in middle of another string

不问归期 提交于 2019-12-07 05:13:25
问题 I am trying to display some text and an icon inside a single string using FontAwesome. Here is what I have: NSString *icon = [NSString fontAwesomeIconStringForIconIdentifier:@"icon-map-marker"]; NSString *locationString = [NSString stringWithFormat:@"%@ %@", icon, otherNormalString]; Basically I want to have the map marker show up in front of the location being displayed. Using FontAwesome should make this really simple but I can't quite get it to work right. Here is also what shows up if I

Can't scroll in UIScrollView as soon as UILabel / other subview added in Storyboard

痴心易碎 提交于 2019-12-07 03:30:37
问题 I encountered the following problem: as soon as I add e.g. a UILabel to my UIScrollView - using the storyboard - the scroll view stops "working" (with that I mean you cannot scroll at all). However adding a subview programmatically the scroll view works fine but since I prefer designing my apps visually with storyboard I would like to solve this mysterious error. Does anyone knows why this error is occurring? Thanks in advance :) PS: I do set the contentSize of my scrollView, so this cannot

Using NSNumberFormatter to format currency in output UILabel

好久不见. 提交于 2019-12-07 03:13:22
问题 NSNumberFormatter * fmt; NSNumber * n; fmt = [ [ NSNumberFormatter alloc ] init ]; n = [ NSNumber numberWithFloat: 10 ]; [ fmt setFormatterBehavior: NSNumberFormatterBehavior10_4 ]; [ fmt setCurrencySymbol: @"$" ]; [ fmt setNumberStyle: NSNumberFormatterCurrencyStyle ]; // NSLog( @"%@", [ fmt stringFromNumber: n ]; [ fmt release ] -(IBAction)buttonPressed1:(id)sender { double currency = [Amount1.text doubleValue] + [Amount2.text doubleValue]; SumCurrency.text = [NSString stringWithFormat:@"%0

UILabel Center contents

柔情痞子 提交于 2019-12-07 01:16:43
问题 Here's my code: UILabel *myLabel; myLabel = [[UILabel alloc] initWithFrame:CGRectMake(20, 0, 300, 480)]; myLabel.lineBreakMode = UILineBreakModeWordWrap; myLabel.numberOfLines = 2; // 2 lines ; 0 - dynamical number of lines myLabel.text = @"Please select at least one image category!"; myLabel.font = [UIFont fontWithName:@"Arial-BoldMT" size: 24.0]; myLabel.center = CGPointMake(self.view.frame.size.width/2, self.view.frame.size.height/2); myLabel.backgroundColor = [UIColor clearColor]; [self

How can I remove UILabel's gray border on the right side?

那年仲夏 提交于 2019-12-06 17:11:55
问题 I have added an UILabel to a custom cell's contentView. I met with a strange side effect. On the right border there is a gray edge. I don't know why. I just added an ordinary UILabel, I have done nothing else. UILabel *label = [[UILabel alloc] initWithFrame:CGRectZero]; label.text = @"value1"; label.textAlignment = UITextAlignmentCenter; [self.contentView addSubview:label]; - (void)layoutSubviews { UILabel *label = [self.contentView.subviews objectAtIndex:i]; label.frame = CGRectMake(…); }

Resize label to fit text amount - Swift

南楼画角 提交于 2019-12-06 17:11:15
问题 Hey :) I have a label and I need to make the width of that label smaller or larger accourding to the text amount, and I found only how to adjust the text to fit the size but the how to adjust the size to fit the text, any ideas ? 回答1: You'll want to do this: myLabel.sizeToFit() As seen here: https://developer.apple.com/documentation/uikit/uiview/1622630-sizetofit This will update the label's frame to fit the content. You can then place it or make any edits after this that you want. 来源: https:

Objective-C: How to animate “Loading…” text on a UILabel

依然范特西╮ 提交于 2019-12-06 16:25:36
问题 In my app I need to display a "Loading" text in an UILabel, repeatedly as follows: Loading Loading. Loading.. Loading... Loading Loading. Loading.. Loading... How can I do it? Any suggestion, please? 回答1: You could easily implement such a behavior yourself – see my example below. But like trojanfoe suggested, I would rather use a nice library like MBProgressHUD or MarqueeLabel - (void) updateLoadingLabel; { if(self.loading) { if([self.labelLoading.text isEqualToString:@"Loading…"]) { self

UILabel Dynamic Font size keep breaking

亡梦爱人 提交于 2019-12-06 15:54:57
I Have CollectionViewCell that has only UILabel(Same bounds as cell). I'm fetching array of fontNames as the CollectionView DataSource : func printFonts() { let fontFamilyNames = UIFont.familyNames() for familyName in fontFamilyNames { let names = UIFont.fontNamesForFamilyName(familyName as! String) fontNames.append(familyName as! String) } } I'm trying to display this font names in one line inside the UILabel , it works in some of the cases but in some not, and i have not idea why. this is how i "adjust" the font inside cellForItemAtIndexPath : cell.lbl_font.adjustsFontSizeToFitWidth = true

Is it safe to add a “stolen” UILabel's layer to some other CALayer's sublayer?

99封情书 提交于 2019-12-06 15:42:13
I read this and this but they don't seem to address the issue. And the answers to this seem to go off a tangent in NSCoding and friends, so ... Consider: - (NSAttributedString *) attributedStringForText: (NSString *) text { NSMutableAttributedString* attrStr = [[NSMutableAttributedString alloc] initWithString:text]; UIFont * bigF = [UIFont fontWithName:@"OpenSans-Extrabold" size:20.0f] ; UIFont * smaF = [UIFont fontWithName:@"OpenSans-Extrabold" size:12.0f] ; [attrStr addAttribute:NSFontAttributeName value:bigF range:(NSRange){0, 3}] ; [attrStr addAttribute:NSFontAttributeName value:smaF range