在程序中,可以通过xib文件中添加UILable,当然,我们也可以通过代码创建,并添加到View中,下面是一个例子,包括:
-创建一个新的UILable
-设置字体,大小,颜色,文字
-设置平移,旋转
代码如下:
UILabel* label = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, self.view.bounds.size.width, self.view.bounds.size.height)]; label.numberOfLines = 2; label.backgroundColor = [UIColor clearColor]; label.textColor = [UIColor greenColor]; label.highlightedTextColor = [UIColor blackColor]; label.textAlignment = UITextAlignmentCenter; label.font = [UIFont systemFontOfSize:12]; //顺时针旋转90度 label.transform = CGAffineTransformMakeRotation( M_PI/2 ); //在x方向平移-260个像素 infoView.transform = CGAffineTransformTranslate(infoView.transform, -260.0f, 0.0f); [self addSubview:label]; [label release];