iPhone开发之各种控件高度自适应

UILabel: 当所给行数比较多内容又少时,内容占据中间位置;但我想的是让其在前面几行、 想想只能用高度自适应来解决

 introduceString = @"我饿接啊放假快乐放假啊的";
introduceLabel = [[UILabel alloc] initWithFrame:CGRectMake(cellViewXCoordinate+17, cellViewYCoordinate+195, 143, 52)];//实际所在区域
introduceLabel.text = [NSString stringWithFormat:@"%@",introduceString];
 //高度自适应
UIFont *font = [UIFont systemFontOfSize:12];
introduceLabel.font = font;
[introduceLabel setNumberOfLines:0];  //关键代码
CGSize constraint = CGSizeMake(143, 52);//总的区域
CGSize size = [introduceString sizeWithFont:font constrainedToSize:constraint lineBreakMode:UILineBreakModeWordWrap];
[introduceLabel setFrame:CGRectMake(cellViewXCoordinate+17, cellViewYCoordinate+195, size.width, size.height)];
[favoriteScrollView addSubview:introduceLabel];

 

UITextView:放在scrollview中 (总感觉有些问题,能用UILabel的话就尽量用UIlabel好了)

UIScrollView *scroll = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, 320, 460)];
    [self.view addSubview:scroll];
    
    UITextView *text = [[UITextView alloc] initWithFrame:CGRectMake(0, 0, 320, 100)];
    text.backgroundColor = [UIColor greenColor];
    [scroll addSubview:text];
    text.editable = NO;
    text.text = @"哒短发地方啊激发俄方啊激发卡的减肥ioahf;金额啊快乐;分局哦啊额好烦额就爱哦放假啊额减肥的;积分卡和大家开发好吧的发第三方的 大幅大家发哈三分efhiajeqpfj去合肥经开区企鹅和放弃jefiohfie发的思考放假企鹅王菲额放假期望hfid放寒假啊粉底哦啊;就疯狂哦恶趣味减肥离开;;阿凡达放假啊为了分官方;放假额qwiofejf啊俄方哈额发黑分j饿的阿胶分开啦阿胶发觉放假啊额; ;阿胶阿飞; 接啊俄方接口;啊激发饿啊减肥;啊额价格佛啊第三届浪费打飞机啊;是否就恶风 饿啊分啊份额噶饿额度高啊恶搞饿啊分啊额啊发饿饿啊 短发的阿飞啊的发掘  解决就就 就就就就就 解决就 哦哦哦  uu 他他有uu uii哦破破破哦iu有 一天 官方gv吧吧吧  你们么";
    text.scrollEnabled = NO;
    UIFont *font = [UIFont systemFontOfSize:20];
    text.font = font;
    CGSize size = [text.text sizeWithFont:font constrainedToSize:CGSizeMake( 320, 9999) lineBreakMode:UILineBreakModeWordWrap];
    text.frame = CGRectMake(0, 0, size.width, size.height+34);
    
    scroll.contentSize = CGSizeMake(size.width, size.height +34);

 

 

posted @ 2012-09-19 21:37  小、  阅读(2639)  评论(0编辑  收藏  举报