label添加手势(触摸改变其背景颜色)

- (BOOL)application:(UIApplication *)application
didFinishLaunchingWithOptions:(NSDictionary *)launchOptions

{

self.window =
[[UIWindowalloc]
initWithFrame:[[UIScreenmainScreen]
bounds]];

UILabel
*lab1=[[UILabelalloc]initWithFrame:CGRectMake(20,
30, 100,
30)];

lab1.text=@"helloworld";

  //设置tag属性

lab1.tag=1;

UITapGestureRecognizer
*tap=[[UITapGestureRecognizeralloc]initWithTarget:selfaction:@selector(randomColor:)];

[lab1 addGestureRecognizer:tap];

lab1.userInteractionEnabled=YES;

[self.window
addSubview:lab1];

self.window.backgroundColor
= [UIColorwhiteColor];

[self.windowmakeKeyAndVisible];

returnYES;

}

-(void)randomColor:(UITapGestureRecognizer
*)gestureRecognizer

{

  //通过tag属性来获取label

UILabel *lab=(UILabel
*)[self.window
viewWithTag:1];

lab.backgroundColor=[UIColorcolorWithRed:arc4random()%256/255.0green:arc4random()%256/255.0blue:arc4random()%256/255.0alpha:1];

}

时间: 2024-08-02 01:09:02

label添加手势(触摸改变其背景颜色)的相关文章

ios点击改变uiview背景颜色

ios点击改变uiview背景颜色是一个再常见不过的需求.第一反应应该不麻烦,于是写了个第一个版本 @interface RespondentUIView() { UIColor * bgColor; } @end @implementation RespondentUIView- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event { bgColor = self.backgroundColor; self.backgr

用JS让下拉框改变网页背景颜色

<HTML> <HEAD> <TITLE>石家庄渣浆泵配件</TITLE> </HEAD> <SCRIPT> <!-- function bgChange(selObj) { newColor = selObj.options[selObj.selectedIndex].text; document.bgColor = newColor; selObj.selectedIndex = -1; } //--> </SC

MFC改变对话框背景颜色

原文链接: http://blog.sina.com.cn/s/blog_59955afc0100spjz.html 方法一:调用CWinApp类的成员函数SetDialogBkColor来实现. ---- 其中函数的第一个参数指定了背景颜色,第二个参数指定了文本颜色.下面的例子是将应用程序对话框设置为蓝色背景和红色文本,步骤如下: ---- ① 新建一个基于Dialog的MFC AppWizard应用程序ExampleDlg. ---- ② 在CExampleDlgApp ::InitInst

C# 改变控制台背景颜色

之前查找静态构造函数相关的问题无意间碰到的一个问题.改变控制台的背景颜色. 1 static void Main(string[] args) 2 { 3 //设置绿色 4 Console.BackgroundColor = ConsoleColor.Green; 5 6 Console.WriteLine("背景色改变了"); 7 8 } 这段代码运行以后是这个样子的.和想要的结果不符合. 所以正确的代码其实是 1 static void Main(string[] args) 2

UI:改变UIView背景颜色

//每隔一秒改变一次颜色 [NSTimer scheduledTimerWithTimeInterval:1 target:self selector:@selector(changeColor) userInfo:nil repeats:YES]; #pragma mark 改变颜色 - (void)changeColor{ //动画开始 [UIView beginAnimations:nil context:nil]; [UIView setAnimationDuration:0.5]; s

VS2012使对话框透明和改变对话框背景颜色或图片背景

在Dlg头文件中public加入: CBrush m_bkBrush; afx_msg HBRUSH OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor); // 在OnInitDialog()中 创建一把黄色的背景刷子 m_bkBrush.CreateSolidBrush(RGB(255,180,100)); 设置对话框透明度 ::SetWindowLong( m_hWnd, GWL_EXSTYLE, GetWindowLong(m_hWnd, GW

Android改变图片背景颜色tint(着色)或 backgroundTint

安卓对图标着色以节省apk体积,网上有很多介绍到的,使用也很简单 <ImageView     android:tint="@android:color/white"     android:backgroundTint="@android:color/black"     /> 平时都这样使用,今天得在代码中改,所以记录一下 第一种 Drawable icon; if (android.os.Build.VERSION.SDK_INT < and

Android笔记:根据进度代码改变progressbar背景颜色,ClipDrawable,LayerDrawable,setProgressDrawable

做个笔记,主要是需要使用ClipDrawable.LayerDrawable: private void setProgressBg(int progress) {     int a = progress * 255 / 100;     int color = Color.argb(a, 255, 90, 147);     ColorDrawable colorDrawable = new ColorDrawable();     colorDrawable.setColor(color)

css中table tr:nth-child(even)改变tr背景颜色: IE7,8无效

例如: .my_table tr:nth-child(even){ background:#E6EDF5; } .my_table tr:nth-child(odd){ background:#F0F5FA; } IE7,8无效,无法识别. 换一种方法: 给需要变色的tr加上class .table_border table tr.even{background: #f8f8fb;} 方法三:jquery实现 $(".nav ul li div a:nth-child(even)").