Ios UILabel-attributedText-setLineHeightMultiple
我使用UILabel来显示文本 问题是,我在不同的IOS版本之间有不同的行距。IOS7.1的空间比IOS8.1小 最好的解决方法是什么?我没有安装所有的模拟器,所以我不知道问题何时出现。有人有解决办法吗?这是当前代码:Ios UILabel-attributedText-setLineHeightMultiple,ios,objective-c,Ios,Objective C,我使用UILabel来显示文本 问题是,我在不同的IOS版本之间有不同的行距。IOS7.1的空间比IOS8.1小 最好的解决方法是什么?我没有安装所有的模拟器,所以我不知道问题何时出现。有人有解决办法吗?这是当前代码: NSString *startGameBasic_title = @"TRACK QUIZ"; // FONT SIZE 20 px NSString *startGameBasic_1 = @"BASIC"; // FONT SIZE 76 px NSS
NSString *startGameBasic_title = @"TRACK QUIZ"; // FONT SIZE 20 px
NSString *startGameBasic_1 = @"BASIC"; // FONT SIZE 76 px
NSString *startGameBasic_2 = @"MODE"; // FONT SIZE 76 px
NSString *startGameBasic_textRe = [NSString stringWithFormat:@"%@\n\n%@\n%@",
startGameBasic_title,
startGameBasic_1,
startGameBasic_2];
// Define general attributes like color and fonts for the entire text
NSDictionary *startGameBasic_attribsRe = @{
NSForegroundColorAttributeName: GENERAL_BACK_BUTTON_COLOR,
NSFontAttributeName:START_VIEW_FONT_SMALL,
NSKernAttributeName:@(0.0f)
};
NSMutableAttributedString *startGameBasic_attributedTextRe = [[NSMutableAttributedString alloc] initWithString:startGameBasic_textRe attributes:startGameBasic_attribsRe];
//TITEL
NSRange startGameBasic_text_title = [startGameBasic_textRe rangeOfString:startGameBasic_title];
[startGameBasic_attributedTextRe setAttributes:@{NSForegroundColorAttributeName:GENERAL_BACK_BUTTON_COLOR,
NSFontAttributeName:START_VIEW_FONT_SMALL,
NSKernAttributeName:@(-0.5f)}
range:startGameBasic_text_title];
//FIRSTROW
NSRange startGameBasic_text_1 = [startGameBasic_textRe rangeOfString:startGameBasic_1];
[startGameBasic_attributedTextRe setAttributes:@{NSForegroundColorAttributeName:GENERAL_BACK_BUTTON_COLOR,
NSFontAttributeName:START_BASIC_BUTTON,
NSKernAttributeName:@(-3.5f)}
range:startGameBasic_text_1];
//SECONDROW
NSRange buttonReStart_text_2 = [startGameBasic_textRe rangeOfString:startGameBasic_2];
[startGameBasic_attributedTextRe setAttributes:@{NSForegroundColorAttributeName:GENERAL_BACK_BUTTON_COLOR,
NSFontAttributeName:START_BASIC_BUTTON,
NSKernAttributeName:@(-2.8f)}
range:buttonReStart_text_2];
// Create NSMutableParagraphStyle object
NSMutableParagraphStyle *startGameBasic_paragraphRe = [[NSMutableParagraphStyle alloc] init];
startGameBasic_paragraphRe.alignment = NSTextAlignmentCenter;
[startGameBasic_paragraphRe setLineHeightMultiple:0.65];
[startGameBasic_attributedTextRe addAttribute:NSParagraphStyleAttributeName value:startGameBasic_paragraphRe range:NSMakeRange(0, [startGameBasic_attributedTextRe length])];
startGameBasic_txt.attributedText = startGameBasic_attributedTextRe;
现在,我有这样做的想法,但也许有更好的方法:
NSMutableParagraphStyle *startGameBasic_paragraphRe = [[NSMutableParagraphStyle alloc] init];
startGameBasic_paragraphRe.alignment = NSTextAlignmentCenter;
float SystemVersion = [[UIDevice currentDevice].systemVersion floatValue];
if (SystemVersion < 8.0)
{
[startGameBasic_paragraphRe setLineHeightMultiple:0.85];
} else {
[startGameBasic_paragraphRe setLineHeightMultiple:0.65];
}
我认为使用UITextView不是一个解决方案,因为我无法设置缩放字体大小。能得到你的帮助就太好了 有人回答吗?