开发者

Getting the number of lines of UIButton

开发者 https://www.devze.com 2023-03-10 02:33 出处:网络
I have a UIButton, and 开发者_StackOverflowI am setting the text of the titleLabel with a string containing several \"\\r\\n\" for new lines.

I have a UIButton, and 开发者_StackOverflowI am setting the text of the titleLabel with a string containing several "\r\n" for new lines.

//From previous logic, you have numLines = 3

NSString *string = [NSString stringWithString:@"this \r\n is a multi-line \r\n button"];

[button setNumberOfLines:numLines]
[button.titleLabel setLineBreakMode:UILineBreakModeWordWrap];

NSLog(@"number of lines = %d", [button.titleLabel numberOfLines]);

but number of lines = 0 is the output - I guess due to the dynamic number of lines with the word wrap.

How can I get the actual number of lines that the title label takes up, after word wrap?

0

精彩评论

暂无评论...
验证码 换一张
取 消