是的,您可以通过制作一个BaseUITextFeild
.h
和.m
文件来执行此操作,如下图所示。
![在此处输入图像描述](https://i.stack.imgur.com/kALbm.jpg)
![在此处输入图像描述](https://i.stack.imgur.com/QKOSz.jpg)
BaseUITextFeild.m
然后只需在文件中添加有关您的设计的以下代码
- (void)awakeFromNib {
[self setupUI];
[self setKeyboardAppearance:UIKeyboardAppearanceAlert];
}
// Function to setup the common UI throught the app.
- (void)setupUI {
[self setContentHorizontalAlignment:UIControlContentHorizontalAlignmentCenter];
[self setContentVerticalAlignment:UIControlContentVerticalAlignmentCenter];
[self setTextAlignment:NSTextAlignmentCenter];
[self setValue:[UIColor colorWithRed:120.0/225.0 green:120.0/225.0 blue:120.0/225.0 alpha:1.0] forKeyPath:@"_placeholderLabel.textColor"];
[self setFont:[UIFont boldSystemFontOfSize:15.0f]];
}
以编程方式生成自定义 UITextField
然后就import "BaseUITextFeild.h"
在ViewController
你想使用它的地方。
BaseUITextFeild *field1 = [[BaseUITextFeild alloc] initWithFrame:CGRectMake(135, 292, 50, 20)];
[self addSubview:field1];
从界面生成器(Storyboard/.XIB)生成自定义 UITextField
添加一个 UITextfield,然后将类更改为您的自定义 TextView 类。
![在此处输入图像描述](https://i.stack.imgur.com/ff7nW.png)
通过应用以下技术,您可以在整个应用程序中使用相同UITextFeild
的技术,只需import BaseUITextFeild.h
.
你也可以使用这个 UITextFieldCategory
按照这两个示例UITextField+withFrame.h和UITextField+ColoredPlaceholder.h。您也可以UITextField
根据自己的需要进行定制。