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
                                                                                       
                                                                                       }
                                           
                                           ];
   
相關文章
相關標籤/搜索