IOS微博项目之UITextField

微博项目中,有个自定义搜索框

主要功能还是继承自UITextField,只是将个属性进行了封装

- (instancetype)initWithFrame:(CGRect)frame {
    self = [super initWithFrame:frame];
    if (self) {
        // 背景
        self.background = [UIImage imageWithNamedResizable:@"searchbar_textfield_background"];
        // 左侧搜索Icon
        UIImageView *iconView = [[UIImageView alloc] initWithImage:[UIImage imageWithNamed:@"searchbar_textfield_search_icon"]];
        iconView.bounds = CGRectMake(0, 0, 30, 15);
        iconView.contentMode = UIViewContentModeCenter;
        self.leftView = iconView;
        self.leftViewMode = UITextFieldViewModeAlways;
        // 提醒文字
        NSMutableDictionary *atts = [[NSMutableDictionary alloc] init];
        [atts setValue:[UIColor grayColor] forKey:NSForegroundColorAttributeName];
        self.attributedPlaceholder = [[NSAttributedString alloc] initWithString:@"待得花开虫破茧,我必化蝶向天飞" attributes:atts];
        // 文字大小
        self.font = [UIFont systemFontOfSize:13];
        // 清除按钮
        self.clearButtonMode = UITextFieldViewModeAlways;
        // 设置返回按钮的类型
        self.returnKeyType = UIReturnKeySearch;
        // 设置键盘返回按钮是否可以点击
        self.enablesReturnKeyAutomatically = YES;
    }
    return self;
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值