2014-10-31 45 views

回答

1
txt_Username = [[UITextField alloc] initWithFrame:CGRectMake(0,40,self.view.frame.size.width/2,32)]; 
txt_Username.borderStyle = UITextBorderStyleRoundedRect; 
txt_Username.font = [UIFont systemFontOfSize:15]; 
txt_Username.placeholder = @"PlacceHolder"; 
txt_Username.autocorrectionType = UITextAutocorrectionTypeNo; 
txt_Username.autocapitalizationType = UITextAutocapitalizationTypeNone; 
txt_Username.keyboardType = UIKeyboardTypeDefault; 
txt_Username.returnKeyType = UIReturnKeyNext; 
txt_Username.clearButtonMode = UITextFieldViewModeWhileEditing; 
txt_Username.contentVerticalAlignment = UIControlContentVerticalAlignmentCenter; 
[txt_Username setLeftViewMode:UITextFieldViewModeAlways]; 
txt_Username.leftView= [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"user"]]; 

txt_Username.borderStyle = UITextBorderStyleNone; 
[txt_Username setBackgroundColor:[UIColor clearColor]]; 
UIView *demoLine = [[UIView alloc] initWithFrame:CGRectMake(txt_Username.frame.origin.x 
                  , txt_Username.frame.origin.y+txt_Username.frame.size.height 
                  , txt_Username.frame.size.width, 1)]; 
[demoLine setBackgroundColor:[UIColor blackColor]];  
[self.view addSubview:demoLine]; 

試試這個會有幫助。

0

您的文本框的邊框樣式更改爲透明的(最左邊的屬性檢查器)。在UIImageView中爲該行使用圖像。在此圖像上方放置您的文本框。或者,不要使用圖像作爲線條,請繪製線條。線條代碼在這裏:

-(void)drawLine:(CGFloat)fromX fromY:(CGFloat)fromY toX:(CGFloat)toX toY:(CGFloat)toY width:(CGFloat)width color:(UIColor *)color 
{ 
    UIBezierPath *path = [UIBezierPath bezierPath]; 
    [path moveToPoint:CGPointMake(fromX, fromY)]; 
    [path addLineToPoint:CGPointMake(toX, toY)]; 

    CAShapeLayer *shapeLayer = [CAShapeLayer layer]; 
    shapeLayer.path = [path CGPath]; 
    shapeLayer.strokeColor = [color CGColor]; 
    shapeLayer.lineWidth = width; 
    shapeLayer.fillColor = [[UIColor clearColor] CGColor]; 

    [self.view.layer addSublayer:shapeLayer]; 
} 

如果您使用避免線條繪製並堅持圖像,則更好。

相關問題