zoukankan      html  css  js  c++  java
  • UITextFiled的输入框改成一条下划线

    在一些程序的界面中,它们的编辑框是一条线,而UITextFiled本身并没有这种style,所有需要我们自己设置.方法还是挺多的

    第一种 ,

    (1).我们可以声明一个类继承与UITextFiled

    (2).需要重写父类的- (void)drawRect:(CGRect)rect方法

    [objc] view plain copy
     
    1. <span style="font-size:18px;">- (void)drawRect:(CGRect)rect {  
    2.     // Drawing code  
    3.     CGContextRef context = UIGraphicsGetCurrentContext();  
    4.     CGContextSetFillColorWithColor(context, [UIColor blackColor].CGColor);  
    5.     CGContextFillRect(context, CGRectMake(0, CGRectGetHeight(self.frame) - 0.5, CGRectGetWidth(self.frame), 0.5));  
    6. }</span>  
    (3)下面再创建uite对象的时候用我们自己声明的这个类来创建,编辑框就会是一条线了

    第二种,

    我们可以创建一个UIView对象,将它的高设为1,贴到UITextFiled上就可以了(view的frame要根据自己的TextField的from来确定)

    UIView *underline = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 100, 1)];

        underline.backgroundColor = [UIColor lightGrayColor];

        [self addSubview:underline];

        [underline release];

     
     

     
     
  • 相关阅读:
    洛谷P2050 美食节
    洛谷P2150 寿司晚宴
    区间最深LCA
    三层交换机
    VLAN 及 GVRP 配置
    GVRP
    VLAN IEEE802.1Q
    以太网端口技术
    网关与路由器
    Quidway S系列交换机
  • 原文地址:https://www.cnblogs.com/xujiahui/p/6554824.html
Copyright © 2011-2022 走看看