IOS 自定義搜索條

自定義搜索條繼承自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);

}

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

推薦閱讀更多精彩內(nèi)容