在UITextView中添加UILabel

3

我使用for-loop以编程方式创建了多个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);
}
2个回答

2

Objective-C 代码:

UILabel *cust_Label = [[UILabel alloc] initWithFrame:CGRectMake(Your_X, Your_Y, Your_Width,Your_Height)];
cust_Label.text=@"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)

你能用Objective-C写吗? - A.M

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接