placeHoder的对齐方式

当咱们设置placeHoder的字体过大的时候,他会和控件的位置居中,可是若是字体偏小,它相对输入框的位置就有点偏上,最后本身找到了解决办法,避免重写的麻烦,但愿与你们一块儿交流一下,代码以下字体

    NSMutableParagraphStyle *style = [field.defaultTextAttributes[NSParagraphStyleAttributeName] mutableCopy];
    
    style.minimumLineHeight = field.font.lineHeight - (field.font.lineHeight - [UIFont systemFontOfSize:14.0].lineHeight) / 2.0;
    
    field.attributedPlaceholder = [[NSAttributedString alloc] initWithString:@"YourTextField Placeholder text"
                                           
                                                                          attributes:@{
                                                                                       
                                                                                       NSForegroundColorAttributeName: [UIColor colorWithRed:255/255.0f green:255/255.0f blue:255/255.0f alpha:0.7f],
                                                                                       
                                                                                       NSFontAttributeName : [UIFont systemFontOfSize:14.0],
                                                                                       
                                                                                       NSParagraphStyleAttributeName : style
                                                                                       
                                                                                       }
                                           
                                           ];
   
相关文章
相关标签/搜索