uilabel

UILabel updates resets view positions

旧巷老猫 提交于 2019-12-11 02:22:57
问题 I have a small problem with updating an UILabel. I tried a "Pong" Game tutorial which uses UIViews for the ball and the players. So I positioned them with the help of the storyboard on their start positions. The game works well, but if I implement a UILabel for displaying the players scores the trouble starts. With every update of the UILabel the UIViews get repositioned to their starting points. Was there something changed in iOS 6? 回答1: I ran into a similar issue. The solution was to turn

UILabel line breaks too early on iOS 11

时光毁灭记忆、已成空白 提交于 2019-12-11 02:01:48
问题 I have an iOS 11 app with a table with cells. In this cells, I have a UILabel. The UILabel seems to "decide" to break the line in a way that keeps the bottom line with at least 2 words (no matter what the BreakLineMode is!). I know about using - Adding non-breaking space (U+00A0) - TOO EXPENSIVE and Using NSAllowsDefaultLineBreakStrategy NO on NSUserDefaults - NOT ALLOWED BY APPLE What can I do to fix this problem? In this image, you can see that the first word in the second line, could

how to solve invalid conversion specifier warning in iphone app

我只是一个虾纸丫 提交于 2019-12-11 02:00:57
问题 I have iphone app in which assigning value to label but when i build this it shows following warning invalid conversion specifier $ here is the code of label assigning values. label1.text=[NSString stringWithFormat:@"%d%$",newvalue1]; 回答1: replace like this why you keep %$ simply place $ symbol label1.text=[NSString stringWithFormat:@"%d$",newvalue1]; 回答2: The %$ is being interpreted as a format string specifier. You need to escape the percent in %$ with two percent signs: %%$ , or remove the

How to get the actual height of a label with auto-height

ⅰ亾dé卋堺 提交于 2019-12-11 01:46:00
问题 I'm aware that this question has appeared in various forms before, but none of the solutions worked out for me... I'm using the Titanium API 2.1.3, and building for iPhone. I use a lot of common JS, so I have this: exports.Header = function(title){ var l = Ti.UI.createLabel({ text: title, height: 'auto', textAlign: 'left', color: '#989898', font: {fontSize: exports.defaultFontSize+10, fontFamily: exports.defaultFont, fontWeight: 'bold'} }); return l; }; And I'm calling the label like so: var

How to set background image for text into UIlabel?

白昼怎懂夜的黑 提交于 2019-12-11 01:31:03
问题 We can set color to text in UILabel. But can we set image to text in UILabel? Can you help me? Thanks all! 回答1: UILabel *lbl = [[UILabel alloc]initWithFrame:CGRectMake(20, 220, 200, 30)]; [lbl setText:@"Hello"]; [lbl setTextColor:[UIColor yellowColor]]; [lbl setBackgroundColor:[UIColor redColor]]; if you need to set image for your UILabel, you can try like this: [lbl setBackgroundColor:[UIColor colorWithPatternImage:[UIImage imageNamed:@""]]]; [self.view addSubview:lbl]; If you want your

Label in uitextfield left view not aligned with the text

此生再无相见时 提交于 2019-12-11 01:14:41
问题 I'm making a custom textField with a label in his left view but the text of the label is not aligned with the text/placeholder of the textField . Here my simple code: class mytextfield: UITextField { override init(frame: CGRect) { super.init(frame: frame) leftViewMode = .always let label = UILabel() label.text = "Hello" leftView = label } required init?(coder aDecoder: NSCoder) { fatalError("init(coder:) has not been implemented") } override func leftViewRect(forBounds bounds: CGRect) ->

NSLineBreakByWordWrapping on First Line but NSLineBreakByTruncatingTail For Second Line?

混江龙づ霸主 提交于 2019-12-11 00:46:29
问题 Is this possible? I want to have a two line label. On the first line, I want it to wrap on words. But for the second line, if the text is too long, I want it to truncate by tail and add the ellipses "..." after. Any ideas on the simplest way to do this? 回答1: In my comment I was wrong about the line break mode. If you just drag out a UILabel, the default line break is Truncate Tail, which is what you want. If you make the label twice as high, and set the lines to 2, the text will wrap, and if

Why do I fail to get textContainer's rect by using “usedRectForTextContainer”

血红的双手。 提交于 2019-12-11 00:41:31
问题 I learned the answer by NAlexN in this Question (Create tap-able "links" in the NSAttributedString of a UILabel?), and write a demo by myself. However, it is unluck for me to work the demo out. Here is my code: (everyone can copy following code to a new project directly to make a test) #import "ViewController.h" @interface ViewController () { UILabel* label; NSTextContainer *textContainer; NSLayoutManager *layoutManager; } @end @implementation ViewController - (void)viewDidLoad { [super

iPhone - Using CGContextShowTextAtPoint to draw special characters

北慕城南 提交于 2019-12-10 23:51:53
问题 I am creating sub class for UILabel to adjust the character spacing. It works well. But when I use special characters as in Spanish or Japanese language, its not writing. Only english characters are written properly. Any solution on how to display them? - (void) drawRect:(CGRect)rect { // Drawing code CGContextRef context = UIGraphicsGetCurrentContext(); CGContextSelectFont (context, [self.font.fontName cStringUsingEncoding:NSUTF8StringEncoding], self.font.pointSize, kCGEncodingMacRoman);

iOS7 - Adjusting font size of multiline label to fit its frame

余生长醉 提交于 2019-12-10 21:58:48
问题 I need to fit a multiline attributed text in a UILabel's frame. Reading this thread How to adjust font size of label to fit the rectangle? I started from Niels' solution in order to work with attributed text. Here's the code: the 't' of 'prospect' is put in a new line, whereas I need the words not to be truncated; in this example I expect the font size to be reduced a little more in order to fit 'prospect in a single line. UILabel *myLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 180