Customizing search bar in iPhone application Development

后端 未结 5 668
梦如初夏
梦如初夏 2021-02-06 17:34

In my application I have to add a search bar at the head of the tableview. I am able to add the searchbar but problem is without adding default search bar of ios can i add my cu

5条回答
  •  挽巷
    挽巷 (楼主)
    2021-02-06 18:08

    I think it's better just set all properties of UISearchBar when it is loaded.

    @interface MySearchBar : UISearchBar
    
    @end
    
    
    @implementation MySearchBar
    
    - (id)initWithFrame:(CGRect)frame
    {
        self = [super initWithFrame:frame];
        if (self) {
            [self myInitialize];
        }
        return self;
    }
    
    -(void)awakeFromNib
    
    {
        [super awakeFromNib];
        [self myInitialize];
    }
    
    -(void)myInitialize
    {
        self.backgroundImage = [UIImage imageNamed:@"image.png"];
    
        for (UIView* subview in self.subviews) {
            if ([subview isKindOfClass:[UITextField class]]) {
                //customize text field
                UITextField* textfield = (UITextField*) subview;
            }
        }
    }
    
    @end
    

提交回复
热议问题