美文网首页iOS开发-UITextFeild
iOS-textField等placeholder 对齐方式

iOS-textField等placeholder 对齐方式

作者: Bc_wh1te_Le1 | 来源:发表于2016-03-14 16:02 被阅读4486次

是不是 经常遇到placeholder 怎么设置对齐方式都是靠上?

UITextField*textField = [[UITextFieldalloc]initWithFrame:CGRectMake(100,100,200,50)];

textField.placeholder=@"搜索附近的办公楼、小区、商业街...";

textField.backgroundColor= [UIColorwhiteColor];

[textFieldsetValue [UIColorcolorWithWhite:0.800alpha:1.000]forKeyPath:@"_placeholderLabel.textColor"];

[textFieldsetValue:[UIFontboldSystemFontOfSize:14]forKeyPath:@"_placeholderLabel.font"];3

textField.contentVerticalAlignment=UIControlContentVerticalAlignmentCenter;

[self.viewaddSubview:textField];

这样解决:

使用 NSParagraphStyle 来增加最小线高度:

NSMutableParagraphStyle *style = [self.addressBar.defaultTextAttributes[NSParagraphStyleAttributeName] mutableCopy];

style.minimumLineHeight = self.addressBar.font.lineHeight - (self.addressBar.font.lineHeight - [UIFont fontWithName:@"Gotham-BookItalic" size:14.0].lineHeight) / 2.0;

self.addressBar.attributedPlaceholder = [[NSAttributedString alloc] initWithString:@"Placeholder text" attributes:@{NSForegroundColorAttributeName: [UIColor colorWithRed:79/255.0f green:79/255.0f blue:79/255.0f alpha:0.5f],NSParagraphStyleAttributeName : style}

];

相关文章

网友评论

    本文标题:iOS-textField等placeholder 对齐方式

    本文链接:https://www.haomeiwen.com/subject/mvpflttx.html