ios - iphone objective-c 以编程方式创建标签

标签 ios iphone alignment

我正在使用动态文本以编程方式创建标签,在标签旁边还有一个 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];

最佳答案

您是否也在以编程方式创建 UITextViewUIImageView?如果是这种情况,您只需要将它们框架的“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/

相关文章:

iphone - iPad\iPhone应用结构

ios - Facebook API : Can I simply read posts from wall without loging in?

ios - 如何在 Xcode 6 中删除预览设备

ios - 在 iOS 上通过 Node js 在推送通知中发送表情符号

iphone - 核心数据不保存我的数据。应用程序关闭后我丢失了所有保存的数据

ios - 使用 AFNetworking 2.0 发布带有数组参数的图像不起作用

html - CSS 对齐文本区域 a

html - 布局取决于元素的数量

html - 无法将某些 html 元素与纯 css 对齐?

iphone - CADisplayLink 时间戳在设备上表现异常