2016-05-04 19 views
0

Ich entwickle eine Anwendung, die textView mit unteren Grenzen für jede Zeile hat, kann ich keine Antworten auf diese Frage auf Google und StackOverflow finden. Also habe ich beschlossen, ich werde eine Frage stellen, ich habe diese Textview: My TextviewUITextView Grenze für jede Zeile

, und ich will es wie folgt aussehen: Original Textview

ich es mache programmatisch so bitte geben Sie nicht mir Storyboard Beispiele, Danke

+0

Bitte überprüfen Sie diese eine -> https: // github .com/mfoxstudio/MFUnderlinedTextView / –

Antwort

0
var textview:UITextView=UITextView() 
for var i:Int = 20 ; i <= Int(textview.frame.size.height) ; i = i + 20 // set 20 you line distance .. change your chooice 
{ 
    let border = CALayer() 
    border.borderColor = UIColor.grayColor().CGColor 
    border.frame = CGRectMake(0, CGFloat(i), textview.frame.size.width*1.5 , 1.0) 
    border.borderWidth = 1.0 
    textview.layer.addSublayer(border) 
    textview.layer.masksToBounds = true 
} 
0

Sie können diesen Code verwenden

-(void)setBorderView:(UITextField*)textField 
{ 
    UIView *borderView = [[UIView alloc]init]; 
    borderView.backgroundColor = [UIColor clearColor]; 
    CGRect frameRectEmail=textField.frame; 


    NSLogVariable(textField); 
    borderView.layer.borderWidth=1; 
    borderView.layer.borderColor=[customColor colorWithHexString:@"8c8b90"].CGColor; 
    borderView.layer.cornerRadius=5; 
    borderView.layer.masksToBounds=YES; 



    UIView *topBorder = [[UIView alloc]init]; 
    topBorder.backgroundColor = [customColor colorWithHexString:@"1e1a36"]; 
    CGRect frameRect=textField.frame; 
    frameRect.size.height=CGRectGetHeight(textField.frame)/1.5; 
    topBorder.frame = frameRect; 
     frameRectEmail.size.width=frameRect.size.width; 
    [borderView setFrame:frameRectEmail]; 

    [_textFieldBackGroundView addSubview:borderView]; 
    [_textFieldBackGroundView addSubview:topBorder]; 
    [_textFieldBackGroundView addSubview:textField]; 

}