码迷,mamicode.com
首页 > 移动开发 > 详细

iOS 修改SearchBar的Textfiled的Cursor游标颜色和字体样式和大小;Disable输入框

时间:2014-09-09 18:20:09      阅读:354      评论:0      收藏:0      [点我收藏+]

标签:http   color   os   io   ar   for   art   cti   代码   

因为Search Bar的游标颜色和Tint颜色是统一的,如果要想将游标的颜色设置为其他颜色,则需要到textfiled内部去修改,对于字体也是同样。

实现代码:

- (void)setSearchBarTextfiled:(UISearchBar *)searchBar{
    for (UIView *view in searchBar.subviews){
        for (id subview in view.subviews){
            if ( [subview isKindOfClass:[UITextField class]] ){
                [(UITextField *)subview setTintColor:[UIColor grayColor]];
                [(UITextField *)subview setFont:[UIFont fontWithName:GENERAL_FONT size:13]];
                return;
            }
        }
    }
}

如果要实现用户不能输入到搜索框中,则需要是textfiled的输入失效:

一种方法是对于整个Searchbar设置Disable,但是这样如果有Scope Button等其他组件的话,也会连同失效:

[searchBar setUserInteractionEnabled:NO];

实现代码:

- (void)enableTextInput:(UISearchBar *)searchBar{
    for (UIView *view in searchBar.subviews){
        for (id subview in view.subviews){
            if ( [subview isKindOfClass:[UITextField class]] ){
                [subview setEnabled:YES];
                return;
            }
        }
    }
}

- (void)disableTextInput:(UISearchBar *)searchBar{
    for (UIView *view in searchBar.subviews){
        for (id subview in view.subviews){
            if ( [subview isKindOfClass:[UITextField class]] ){
                [subview setEnabled:NO];
                return;
            }
        }
    }
}
参考链接:

http://stackoverflow.com/questions/9968595/how-to-enable-cancel-button-with-uisearchbar

http://stackoverflow.com/questions/11606007/change-uitextfield-and-uitextview-cursor-caret-color

http://stackoverflow.com/questions/2190352/change-color-of-cursor-in-text-field

http://stackoverflow.com/questions/9169049/disable-uisearchbar

iOS 修改SearchBar的Textfiled的Cursor游标颜色和字体样式和大小;Disable输入框

标签:http   color   os   io   ar   for   art   cti   代码   

原文地址:http://blog.csdn.net/willyang519/article/details/39158679

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!