IOS 自定义搜索条

作者: 小暖风 | 来源:发表于2017-08-20 09:20 被阅读25次

    自定义搜索条继承自UITextField。

    -(instancetype)initWithFrame:(CGRect)frame{

    self= [superinitWithFrame:frame];

    if(self) {

    self.backgroundColor=HEX_COLOR(0xffffff);

    self.layer.cornerRadius=14;

    self.layer.masksToBounds=YES;

    NSAttributedString* placeString = [[NSAttributedStringalloc]initWithString:@"输入商家名、品类或商圈"attributes:@{NSFontAttributeName:[UIFontsystemFontOfSize:12.0f],NSForegroundColorAttributeName:HEX_COLOR(0xc4c4c4)}];

    self.attributedPlaceholder= placeString;

    //图片距离左边14

    UIImageView*searchIcon = [[UIImageViewalloc]initWithImage:[UIImageimageNamed:@"JHLivePlayBundle.bundle/search.tiff"]];

    searchIcon.frame=CGRectMake(14, (frame.size.height-12) /2,12,12);

    UIView* leftView = [[UIViewalloc]initWithFrame:CGRectMake(0,0,26, frame.size.height)];

    [leftViewaddSubview:searchIcon];

    self.leftView= leftView;

    self.leftViewMode=UITextFieldViewModeAlways;

    }

    returnself;

    }

    - (CGRect)placeholderRectForBounds:(CGRect)bounds{

    returnCGRectInset(bounds,34,4);

    }

    相关文章

      网友评论

        本文标题:IOS 自定义搜索条

        本文链接:https://www.haomeiwen.com/subject/zftfdxtx.html