UILable文字竖排的方法汇总

1:对lable做旋转


2.label.text = @"请\n竖\n直\n方\n向\n排\n列";

label.numberOfLines = [label.text length]; 



3.NSString* text = @"一";
UIFont* font = [UIFont systemFontOfSize:14.0]; 
CGSize size = [text sizeWithFont:font constrainedToSize:CGSizeMake(320, 2000.0) lineBreakMode:UILineBreakModeWordWrap]; 
w = size.width;//一个汉字的宽度
str是你要显示的字串
CGSize size = [str sizeWithFont:font constrainedToSize:CGSizeMake(w, 2000.0) lineBreakMode:UILineBreakModeWordWrap]; 
h = size.height;
uilable *lable = [[uilable alloc] initwithframe:cgrectmake(0,0,w,h)];
lable.text = str;



4.NSString* str = @"去年今日此门中,人面桃花相映红;人面不知何处去,桃花依旧笑春风。";
    UIFont* font = [UIFont fontWithName:@"Geeza Pro" size:25];
    CGSize size = [str sizeWithFont:font constrainedToSize:CGSizeMake(25.0f, 460-44) lineBreakMode:NSLineBreakByWordWrapping];
    NSLog(@"size.height=%f,%f",size.height,size.width);
    NSMutableArray* array = [[NSMutableArray alloc]initWithCapacity:0];
    for (int i = 0; i < 4; i ++) {
        NSString* substr=[str substringWithRange:NSMakeRange(i*8, 8)];
        [array addObject:substr];
    }
    for (int i = 0;i < array.count; i++) {
        UILabel* label = [[UILabel alloc]initWithFrame:CGRectMake(220-(size.width+15)*(i+1),10, size.width, size.height)];
        label.text = [array objectAtIndex:i];
        label.numberOfLines = 0;
        label.font = font;
        label.textColor = [UIColor purpleColor];
        label.backgroundColor = [UIColor clearColor];
        label.shadowColor = [UIColor colorWithWhite:0.4 alpha:0.8];
        label.shadowOffset = CGSizeMake(1.0f, 2.0f);
        [self.view addSubview:label];
        [label release];
    }
    [array release]; 


5.    CGRect rect1 = CGRectMake(0, 0, 50, 120);
    UILabel *localLbl = [[UILabel alloc] initWithFrame:rect1];
    localLbl.text = @"本\n地\n音\n乐";
    localLbl.lineBreakMode = NSLineBreakByWordWrapping;

你可能感兴趣的:(ios)