如何将UITextview设置为喜欢Rounded Rect文本字段? [英] How to style UITextview to like Rounded Rect text field?

查看:69
本文介绍了如何将UITextview设置为喜欢Rounded Rect文本字段?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用文本视图作为评论作曲家。

I am using a text view as a comment composer.

在属性检查器中,我找不到任何类似边框样式的属性,以便我可以使用圆角矩形,类似于 UITextField

In the properties inspector I can't find anything like a border style property so that I can make use a rounded rect, something like UITextField.

所以,问题是:我如何设置<$ c的样式$ c> UITextView 像 UITextField ,带有舍入的矩形?

So, the question is: How can I style a UITextView like a UITextField with a rounded rect?

推荐答案

您不必选择隐式样式,它涉及使用 QuartzCore 框架编写一些代码:

There is no implicit style that you have to choose, it involves writing a bit of code using the QuartzCore framework:

//first, you
#import <QuartzCore/QuartzCore.h>

//.....

//Here I add a UITextView in code, it will work if it's added in IB too
UITextView *textView = [[UITextView alloc] initWithFrame:CGRectMake(50, 220, 200, 100)];

//To make the border look very close to a UITextField
[textView.layer setBorderColor:[[[UIColor grayColor] colorWithAlphaComponent:0.5] CGColor]];
[textView.layer setBorderWidth:2.0];

//The rounded corner part, where you specify your view's corner radius:
textView.layer.cornerRadius = 5;
textView.clipsToBounds = YES;

它仅适用于OS 3.0及更高版本,但我想现在它仍然是事实上的平台。

It only works on OS 3.0 and above, but I guess now it's the de facto platform anyway.

这篇关于如何将UITextview设置为喜欢Rounded Rect文本字段?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆