大佬教程收集整理的这篇文章主要介绍了ios – 垂直居中UITextField的attributionPlaceholder,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
这就是我在做的事情:
self.addressBar = [[UITextField alloc] initWithFrame: CGRectMake(...)]; self.addressBar.BACkgroundColor = [UIColor whiteColor]; self.addressBar.attributedPlaceholder = [[NSAttributed@R_197_10495@ng alloc] initWith@R_197_10495@ng:@"Placeholder text" attributes:@{ NSForegroundColorAttributename: [UIColor colorWithRed:79/255.0f green:79/255.0f blue:79/255.0f alpha:0.5f],NSFontAttributename : [UIFont fontWithName:@"Gotham-BookItalic" size:14.0],} ]; self.addressBar.delegate = self; self.addressBar.contentVerticalAlignment = UIControlContentVerticalAlignmentCenter; [self.view addSubview:self.addressBar];
以下是发生的事情:
很明显,这是因为UITextFieldLabel的高度比UItextField本身小10px,但我似乎无法改变它.
这只发生在使用attributionPlaceholder时;默认的占位符属性工作得很好.
有任何想法吗?
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 = [[NSAttributed@R_197_10495@ng alloc] initWith@R_197_10495@ng:@"Placeholder text" attributes:@{ NSForegroundColorAttributename: [UIColor colorWithRed:79/255.0f green:79/255.0f blue:79/255.0f alpha:0.5f],NSParagraphStyleAttributename : style } ];
您还可以覆盖 – (CGRect)placeholderRectForBounds:(CGRect)边界; UITextField子类中的方法.
它很乱,但它的工作原理:)
以上是大佬教程为你收集整理的ios – 垂直居中UITextField的attributionPlaceholder全部内容,希望文章能够帮你解决ios – 垂直居中UITextField的attributionPlaceholder所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。