xcode 文本字段的背景透明度

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/11168347/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-15 00:40:08  来源:igfitidea点击:

Background transparancy of a textfield

iphonexcodeuitextfield

提问by Alippo

I have an application that contains a textfield.

我有一个包含文本字段的应用程序。

Is there a way to change background transparency of this textfield in code?

有没有办法在代码中更改此文本字段的背景透明度?

回答by Ajay

Yes you can do it.

是的,你可以做到。

You can set transparency by setting its alpha. You can pic color code with digital color meter ( its a inbuilt application in mac).

您可以通过设置其 alpha 来设置透明度。您可以使用数字色度计(它是 mac 中的内置应用程序)绘制颜色代码。

if you set alpha 1 then there will be no transparency. set transparency according to your need (set alpha less then 1).

如果您设置 alpha 1,则将没有透明度。根据您的需要设置透明度(设置 alpha 小于 1)。

Try this:

尝试这个:

textfield.backgroundColor=[[UIColor colorWithRed:208.0/255.0 green:15.0/255.0 blue:202.0/255.0 alpha:0.6] CGColor];

回答by Nirav Mehta

You can set with below mentioned code in Xamarin

您可以在 Xamarin 中使用以下提到的代码进行设置

txtNumber.BackgroundColor = UIColor.White;
txtNumber.Alpha = 0.5f;

Reference 1: transparent UITextViewReference 2: How do I create a transparent UITextField?

参考 1:透明 UITextView参考 2:如何创建透明 UITextField?

Similary:

类似:

txtNumber.BackgroundColor = UIColor.Clear;

txtNumber.BackgroundColor = UIColor.Clear;

回答by Paras Joshi

Just put bellow code for white background

只需为白色背景放置波纹管代码

[yourTextField setBackgroundColor:[UIColor whiteColor]];

or if want to clear Color then bellow code

或者如果要清除颜色,则使用以下代码

 [yourTextField setBackgroundColor:[UIColor clearColor]];

so simple

很简单

:)

:)

回答by Hector

use Custom UITextField

使用自定义 UITextField

UITextField *yourTextField= [[UITextField alloc] initWithFrame:frame];
yourTextField.borderStyle = UITextBorderStyleNone;
[yourTextField setBackgroundColor:[UIColor clearColor]];