【发布时间】:2017-03-24 07:18:18
【问题描述】:
我正在创建一个提交反馈的 IOS 表单。
我想让占位符文本在文本字段中垂直居中,水平左对齐
我试过了
- (void)drawPlaceholderInRect:(CGRect)rect {
[RGB(36, 84, 157) setFill];
UIFont *font = [UIFont SingPostLightItalicFontOfSize:_placeholderFontSize fontKey:kSingPostFontOpenSans];
NSMutableParagraphStyle *paragraphStyle = [[NSParagraphStyle defaultParagraphStyle] mutableCopy];
paragraphStyle.lineBreakMode = NSLineBreakByWordWrapping;
paragraphStyle.alignment = NSTextAlignmentLeft;
NSDictionary *attributes = @{ NSFontAttributeName: font,
NSParagraphStyleAttributeName: paragraphStyle,
NSForegroundColorAttributeName: [UIColor blackColor]};
[[self placeholder] drawInRect:rect withAttributes:attributes];
}
但占位符文本位于垂直顶部。我们如何才能获得金牌。非常感谢
【问题讨论】:
-
rect的值是多少,它是否覆盖了控件的整个高度?或者只是占位符文本的一行高度? -
hi rect 是保持文本域的框架
-
不会使用自动布局,
UITextField和 UITextField 的placeholder属性更容易吗? UITextField 已经为您将文本垂直居中对齐。内阴影会是个问题,我不知道如何生成内阴影,我知道如何使用代码生成外阴影。 -
嗨,它是一个没有情节提要或笔尖的旧项目。全部在代码中。 - (void)drawPlaceholderInRect:(CGRect)rect 是文本字段中的方法
-
您不需要使用故事板或笔尖来进行自动布局。您可以纯粹在代码中完成。
标签: ios objective-c uitextfield placeholder