{"id":548,"date":"2014-08-19T15:59:56","date_gmt":"2014-08-19T07:59:56","guid":{"rendered":"http:\/\/www.yusian.com\/blog\/?p=548"},"modified":"2016-07-15T14:39:44","modified_gmt":"2016-07-15T06:39:44","slug":"%e8%87%aa%e5%ae%9a%e4%b9%89uisearchbar-%e9%80%82%e9%85%8dios6%e5%92%8cios7","status":"publish","type":"post","link":"https:\/\/www.yusian.com\/blog\/project\/2014\/08\/19\/155956548.html","title":{"rendered":"\u81ea\u5b9a\u4e49UISearchBar \u9002\u914dIOS6\u548cIOS7"},"content":{"rendered":"<p>\u8003\u8651\u5230\u7edf\u4e00ios6\u4e0eios7\u7684\u754c\u9762\u98ce\u683c\uff0cUISearchBar\u901a\u8fc7\u91cd\u81ea\u5b9a\u4e49\u6765\u5b9e\u73b0\uff0c\u91cd\u5199\u4e00\u4e2a\u7c7b\u7ee7\u627f\u81eaUISearchBar<\/p>\n<p><strong>1\u3001\u6548\u679c\u56fe\uff1a<\/strong><\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone  wp-image-550\" src=\"http:\/\/www.yusian.com\/blog\/wp-content\/uploads\/2016\/07\/QQ20140819-1@2x.png\" alt=\"QQ20140819-1@2x\" width=\"453\" height=\"91\" \/><\/p>\n<p><strong>2\u3001\u90e8\u5206\u4ee3\u7801\uff1a<\/strong><br \/>\n\u9644\u6ce8\u91ca\u8bf4\u660e<\/p>\n<pre lang=\"objc\" line=\"1\">SASearchBar.h\n#import &lt;UIKit\/UIKit.h&gt;\n\n@interface SASearchBar : UISearchBar\n\n@property (nonatomic, strong)   UITextField     *textField;\n\n@property (nonatomic, strong)   UIButton        *searchBtn;\n\n@end<\/pre>\n<p>SASearchBar.m<!--more--><\/p>\n<pre lang=\"objc\" line=\"1\">#import \"SASearchBar.h\"\n@implementation SASearchBar\n#pragma mark \u521d\u59cb\u5316\n- (id)initWithFrame:(CGRect)frame\n{\n    if (self = [super initWithFrame:frame]) {\n        \/\/ \u8bbe\u7f6e\u80cc\u666f\u8272\u4e3a\u900f\u660e\uff0c\u8fd9\u53e5\u5728ios6\u4e2d\u5f88\u91cd\u8981\uff01\uff01\n        self.backgroundColor = [UIColor clearColor];\n        self.placeholder = @\"\u641c\u7d22\u53f7\u7801\u6216\u59d3\u540d\";\n    }\n    return self;\n}\n\n#pragma mark \u8c03\u6574\u5b50\u63a7\u4ef6\n- (void)layoutSubviews\n{\n    [super layoutSubviews];\n    \n    UIView *baseView = iOS7 ? [self.subviews firstObject] : self;\n    \n    \/\/ \u79fb\u9664\u80cc\u666f\u56fe\u7247\n    [[baseView.subviews firstObject] removeFromSuperview];\n    \n    \/\/ \u83b7\u53d6TextField\n    self.textField = [baseView.subviews firstObject];\n    self.textField.leftView = nil;\n    self.textField.background = nil;\n    self.textField.backgroundColor = [UIColor clearColor];\n    self.textField.frame = CGRectMake(0, 0, baseView.frame.size.width - 30, 44);\n    \n    \/\/ \u521b\u5efa\u641c\u7d22\u6309\u94ae\n    self.searchBtn = [UIButton buttonWithType:UIButtonTypeCustom];\n    UIImage *searchIcn = [UIImage imageNamed:@\"icon_invite_search_btn.png\"];\n    [self.searchBtn setImage:searchIcn forState:UIControlStateNormal];\n    self.searchBtn.frame = CGRectMake(baseView.frame.size.width - 30, 10, 20, 20);\n    [baseView addSubview:self.searchBtn];\n    \n    NSLog(@\"%@\", self.subviews);\n}\n\n#pragma mark \u7ed8\u5236\u80cc\u666f\u56fe\u7247\n- (void)drawRect:(CGRect)rect\n{\n    UIImage *image = [UIImage resizeImage:@\"textField_line_selected.png\"];\n    [image drawInRect:CGRectMake(0, 0, rect.size.width, rect.size.height)];\n}\n@end<\/pre>\n<p><strong>3\u3001\u7d20\u6750\u4e0b\u8f7d:<\/strong><a href=\"http:\/\/www.yusian.com\/blog\/wp-content\/uploads\/2016\/07\/Resource.zip\">Resource<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u8003\u8651\u5230\u7edf\u4e00ios6\u4e0eios7\u7684\u754c\u9762\u98ce\u683c\uff0cUISearchBar\u901a\u8fc7\u91cd\u81ea\u5b9a\u4e49\u6765\u5b9e\u73b0\uff0c\u91cd\u5199\u4e00\u4e2a\u7c7b\u7ee7\u627f\u81eaUISearchBar 1\u3001\u6548\u679c\u56fe\uff1a 2\u3001\u90e8\u5206\u4ee3\u7801\uff1a \u9644\u6ce8\u91ca\u8bf4\u660e SASearchBar.h #import &lt;UIKit\/UIKit.h&gt; @interface SASearchBar : UISearchBar @property (nonatomic, strong) UITextField *textField; @property (nonatomic, strong) UIButton *searchBtn; @end SASearchBar.m<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[11],"tags":[17],"class_list":["post-548","post","type-post","status-publish","format-standard","hentry","category-project","tag-skill"],"_links":{"self":[{"href":"https:\/\/www.yusian.com\/blog\/wp-json\/wp\/v2\/posts\/548","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.yusian.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.yusian.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.yusian.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.yusian.com\/blog\/wp-json\/wp\/v2\/comments?post=548"}],"version-history":[{"count":0,"href":"https:\/\/www.yusian.com\/blog\/wp-json\/wp\/v2\/posts\/548\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.yusian.com\/blog\/wp-json\/wp\/v2\/media?parent=548"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.yusian.com\/blog\/wp-json\/wp\/v2\/categories?post=548"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.yusian.com\/blog\/wp-json\/wp\/v2\/tags?post=548"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}