2016-05-04 12 views
2

Ich habe mehrere UITextView, die ich mit einer for-Schleife programmgesteuert erstellt habe. Ich versuche, eine UILabel an der oberen linken Ecke von jedem UITextView auch hinzuzufügen. Wie kann ich das tun?UILabel zu UITextView hinzufügen

Mein UITextView Code:

for (int i = 0; i < 10; i++){ 
    UITextView *textView = [[UITextView alloc] initWithFrame:CGRectMake(0, yPos, 375,height)]; 
    [textView setBackgroundColor:[UIColor lightGrayColor]]; //set different property like this 
    UIColor *borderColor = [UIColor colorWithRed:204.0/255.0 green:204.0/255.0 blue:204.0/255.0 alpha:1.0]; 
    textView.layer.borderColor = borderColor.CGColor; 
    textView.layer.borderWidth = 1.0; 
    textView.layer.cornerRadius = 5.0; 
    textView.textAlignment=NSTextAlignmentRight; 
    textView.editable=NO; 

    [CommentScrooll addSubview:textView ]; 
    // CommentScroll Is the name of my viewcontroller 
    yPos += (height + padding); 
} 

Antwort

1

Objective-C-Code: -

UILabel *cust_Label = [[UITextView alloc] initWithFrame:CGRectMake(Your_X, Your_Y, Your_Width,Your_Height)]; 
[email protected]"Your Text"; 
[textView addSubview: cust_Label]; 
1

Ich habe noch nie eine UILabel zu einem UITextView vor, aber ich dies nur getestet und es funktionierte hinzugefügt. Dies ist die allgemeine Idee:

let label = UILabel(frame: CGRect(x: 0, y: 0, width: 100, height: 20)) 
label.text = "My Label" 
textView.addSubview(label) 
+0

ca Sie schreiben es in Objective-c bitte? –

+0

@ A.M schau auf meinen Code. –