iphone - 编辑 : UITextView Label is Cut in Half (Horizontally)

标签 iphone objective-c ios uibutton contentsize

我需要帮助解决这个特殊问题。我有一个多项选择题应用程序,我可以选择 UITextview。有时,无论出于何种原因,选项 D 都会被减半。

截图: Choice D is halved!

不知道这里发生了什么。我基本上让 UITextView 框架调整到它的 contentSize。

                CGRect dFrame = choiceD.frame;
                dFrame.size.height = choiceD.contentSize.height;
                choiceD.frame = dFrame;

有什么想法吗?提前致谢。

最佳答案

计算字符串的大小:

    NSString *choiceDString = @"Equal the present value....";
    CGSize size = [choiceDString sizeWithFont:[UIFont systemFontOfSize:CHOICE_FONT_SIZE] constrainedToSize:CGSizeMake(CHOICE_WIDTH, 100000)];

初始化一个标签来满足选择字符串:

    UILabel *choiceDLabel = [[UILabel alloc] initWithFrame:CGRectMake(0,0,size.width,size.height)];
    choiceDLabel.text= choiceDString;

为按钮添加 subview 标签:

    [button addSubview:choiceLabel];

关于iphone - 编辑 : UITextView Label is Cut in Half (Horizontally),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10184495/

相关文章:

iphone - 搜索栏的 iOS 色调文本字段背景

ios - 在非 Cocos2d 应用程序上使用 Kamcord

ios - 从 URL 在应用程序中打开文件

ios - SWRevealViewController 正确关闭以导航到下一个 Storyboard?

ios - iOS中的进程间通信

cocoa-touch - iOS App 的非英语默认语言?

iphone - 使用 Xcode for iPhone dev 将字符串写入文本文件

iphone - 如何在 UITapGestureRecognizer 中的 @selector 中传递参数?

iphone - 核心数据,尝试使用 NSPredicate 来过滤 toMany 关系集但得到 "to-many key not allowed here"错误

mysql - 使用我的 iOS 应用程序连接到 MySQL 数据库