Placeholder text not centered for UITextField created programmatically

后端 未结 4 1953
粉色の甜心
粉色の甜心 2020-12-08 04:14

I am creating a UITextField programmatically and placing it inside a UIView. The font size is set to 15.0f (system font). But the placeholder that appears is not centered in

4条回答
  •  鱼传尺愫
    2020-12-08 04:40

    I was using just the color, but we need to set the font as well.

    This one worked for me:

    [[UITextField appearanceWhenContainedIn:[UISearchBar class], nil] setDefaultTextAttributes:
    @{
         NSForegroundColorAttributeName:[UIColor whiteColor], 
         NSFontAttributeName: [UIFont systemFontOfSize:12]
    }];
    

提交回复
热议问题