zoukankan      html  css  js  c++  java
  • UISearchBar的使用心得

    UISearchBar是无法修改其  textField的大小的

    http://stackoverflow.com/questions/556814/changing-the-size-of-the-uisearchbar-textfield

    The text field used in UISearchBar is a subclass of UITextField called UISearchBarTextField.

    AFAIK, there's no way to resize a UISearchBarTextField using the public API, and the private APIdoesn't reveal much either.

    Maybe you can take a look at UISearchBarTextField's subviews, if it has any.

    - (void)layoutSubviews {
    	UITextField *searchField;
    	NSUInteger numViews = [self.subviews count];
    	for(int i = 0; i < numViews; i++) {
    		if([[self.subviews objectAtIndex:i] isKindOfClass:[UITextField class]]) { //conform?
    			searchField = [self.subviews objectAtIndex:i];
    		}
    	}
    	if(!(searchField == nil)) {
    		searchField.textColor = [UIColor redColor];
    	//	[searchField setBackground: [UIImage imageNamed:@"esri.png"] ];
    		[searchField setBorderStyle:UITextBorderStyleRoundedRect];
    		UIImage *image = [UIImage imageNamed: @"esri.png"];
    		UIImageView *iView = [[UIImageView alloc] initWithImage:image];
    		searchField.leftView = iView;
    		[iView release];
    
    	}
    
    	[super layoutSubviews];
    }


    // 设置搜索栏输入框形状
        UITextField *searchField = nil;
        for (UIView *subview in searchBar.subviews) {
            if ([subview isKindOfClass:[UITextField class]]) {
                searchField = (UITextField *)subview;
                break;
            }
        }
        if (searchField) {
            searchField.borderStyle = UITextBorderStyleRoundedRect;
        }
        // 设置搜索栏输入框边框颜色
        searchField.layer.cornerRadius = 8.0f;
        searchField.layer.masksToBounds = YES;
        searchField.layer.borderColor = [[UIColor colorWithRed:118.0f/255.0f green:193.0f/255.0f blue:220.0f/255.0f alpha:1.0f]CGColor];
        searchField.layer.borderWidth = 2.0f;






  • 相关阅读:
    javascript:history.go()和history.back()的区别
    ASP.NET26个性能优化方法
    20 个 jQuery 分页插件和教程,附带实例
    JQuery中$.ajax()方法参数详解
    记住键盘快捷键大全 提高电脑操作速度
    URL重写案例
    url重写(伪静态)IIS配置图解
    URL重写的优缺点分析
    C# GUID的使用
    js中的编码与解码
  • 原文地址:https://www.cnblogs.com/easonoutlook/p/2642822.html
Copyright © 2011-2022 走看看