我正在使用动态文本以编程方式创建标签,在标签旁边还有一个 TextView ,它是动态内容,在 TextView 旁边有一个 ImageView 。这三个没有正确对齐,
_textView = [[[JSTwitterCoreTextView alloc] initWithFrame:CGRectMake(10,60,self.view.frame.size.width,130)] autorelease];
_textView.textColor=[UIColor whiteColor];
_textView.linkColor=[UIColor lightTextColor];
[self.view addSubview:_textView];
CGFloat Lsize=_textView.bounds.size.height+_textView.bounds.origin.y;
//CGFloat width = [UIScreen mainScreen].bounds.size.width - 50;
//CGFloat height = [self textHeight:text] + 10;
//CGRect frame = CGRectMake(10.0f, 10.0f, width, height);
startLine=[[UILabel alloc]initWithFrame:CGRectMake(0,Lsize, 320, 2)];
[self.view addSubview:startLine];
最佳答案
您是否也在以编程方式创建 UITextView
和 UIImageView
?如果是这种情况,您只需要将它们框架的“x”或“y”(取决于水平或垂直对齐方式)设置为相同的值,如下所示:
// Vertical alignment
UILabel *label = [[UILabel alloc] initWithFrame: CGRectMake(labelX, y, labelWidth, labelHeight)];
UITextView *text = [[UITextView alloc] initWithFrame: CGRectMake(textX, y, textWidth, textHeight)];
UIImageView *image = [[UIImageView alloc] initWithFrame: CGRectMake(imageX, y, imageWidth, imageHeight)];
关于ios - iphone objective-c 以编程方式创建标签,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9701698/