2012-03-14 26 views
2

我使用动态文本以编程方式创建标签,并在标签旁边显示了另一个textview,它是动态内容,文本视图旁边有一个imageview。这三个不对齐正确,iphone objective-c以编程方式创建标签

_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]; 

回答

0

你创建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)]; 
+0

是以编程方式编程 – 2012-03-14 14:44:07

0

我已经成功与调用sizeToFit在UILabel对象上,然后定位标签。首先使用适当的内容和其他设置来设置标签,然后调用sizeToFit,然后将它们移动到适当的位置。例如,我使用此代码的大小和排列两个标签:

[countDescriptorLabel sizeToFit]; 
[countOutputLabel sizeToFit]; 
    [countOutputLabel setFrame:CGRectMake(countDescriptorLabel.frame.origin.x + countDescriptorLabel.frame.size.width, countOutputLabel.frame.origin.y, countOutputLabel.frame.size.width, countOutputLabel.frame.size.height)]; 

根据不同的内容,我会经常有一个空间作为第一个标签的文本的最后一个字符,使间距工作的权利。

相关问题