UITextFiled 입력란이 밑줄로 변경됨

939 단어 UI
일부 프로그램의 인터페이스에서, 그들의 편집 상자는 하나의 선이고, UITExtFiled 자체에는 이런 스타일이 없으며, 모든 것은 우리가 설정해야 한다.방법이 많네요.
첫 번째,
(1).클래스 상속 및 UITExtFiled 선언 가능
(2).부모 클래스를 다시 쓰는 - (void) drawRect: (CGRect) rect 방법
- (void)drawRect:(CGRect)rect {
    // Drawing code
    CGContextRef context = UIGraphicsGetCurrentContext();
    CGContextSetFillColorWithColor(context, [UIColor blackColor].CGColor);
    CGContextFillRect(context, CGRectMake(0, CGRectGetHeight(self.frame) - 0.5, CGRectGetWidth(self.frame), 0.5));
}

(3) 다음에 uite 대상을 만들 때 우리가 설명한 이 클래스로 만들면 편집 상자가 한 줄이 됩니다
두 번째,
UIView 대상을 만들 수 있습니다. UITExtFiled에 1로 설정하면 됩니다. (view의 프레임은 자신의 TextField의from에 따라 결정됩니다.)
UIView *underline = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 100, 1)];
    underline.backgroundColor = [UIColor lightGrayColor];
    [self addSubview:underline];
    [underline release];

좋은 웹페이지 즐겨찾기