2016-05-04 4 views
2

У меня есть несколько UITextView, которые я создал с программным обеспечением для цикла. Я пытаюсь добавить UILabel в верхний левый угол каждого UITextView. Как я могу это сделать?Добавить UILabel в UITextView

Мой UITextView код:

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); 
} 

ответ

1

Objective-C код: -

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

Я никогда не добавил UILabel к UITextView раньше, но я только проверил это, и она работала. Это общая идея:

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

ча вы пишете, что в Objective-C, пожалуйста? –

+0

@ A.M Посмотрите на мой код. –