我的手机6s开机白苹果无限重启启,但是强制开机 能开开 一松开那两个建 几秒钟又

UIButton 控件使用
来源:open开发经验库
//login button
UIButton *_loginB
@property (strong,nonatomic)UIButton *loginB
// .m 中实现设置按钮
@synthesize loginBtn = _loginB//使用备份变量名
//设置按钮的
self.loginBtn = [UIButton buttonWithType:UIButtonTypeRoundedRect];
buttonWithType:
定义button按钮的外形 
六种定义button类型: 下面有图解 
UIButtonTypeCustom = 0,
无类型 
UIButtonTypeRoundedRect,
四个角是圆弧
型的 
UIButtonTypeDetailDisclosure, 
UIButtonTypeInfoLight, 
UIButtonTypeInfoDark, 
UIButtonTypeContactAdd, 
//定义button按钮在frame上的坐标(位置),和这个按钮的宽/高
self.loginBtn.frame = CGRectMake(40, 200, 80, 30);
[self.loginBtn setTitle:@"Login" forState:UIControlStateNormal];
常用的属性: 
设置button按钮的名称 
setImage: [UIImage imageNamed:@"图名"]
添加图片 
setTitleColor:[UIColor redColor]
设置字体颜色 
forState 设置 按钮点击前后的状态
: 下有图解 
UIControlStateHighlighted 
UIControlStateSelected 
UIControlStateDisabled 
UIControlStateNormal 
// 为按钮添加一个动作
如果点击的话执行的方法
[self.loginBtn addTarget:self action:@selector(Login:) forControlEvents:UIControlEventTouchUpInside];
//把button控件添加到view中显示
[self.view addSubview:self.loginBtn];
//执行动作的方法
-(IBAction)Login:(id)
六种定义button类型: 
UIButtonTypeCustom = 0,
无类型
UIButtonTypeRoundedRect,
四个角是圆弧
UIButtonTypeDetailDisclosure
UIButtonTypeInfoLight
UIButtonTypeInfoDark
UIButtonTypeContactAdd
forState 设置 按钮点击前后的状态
点击后
UIControlStateHighlighted
UIControlStateSelected
UIControlStateDisabled
UIControlStateNormal
转自:http://blog.csdn.net/like7xiaoben/article/details/;
免责声明:本站部分内容、图片、文字、视频等来自于互联网,仅供大家学习与交流。相关内容如涉嫌侵犯您的知识产权或其他合法权益,请向本站发送有效通知,我们会及时处理。反馈邮箱&&&&。
学生服务号
在线咨询,奖学金返现,名师点评,等你来互动自定义UIButton--iPhone按钮控件点击效果写法
当我们自定义了一个UIButton时,如果采用重绘的方式,将drawRect事件重写了,原有自带的点击的效果就没有了,这时,我们也要自己来重新写的。
例如下面效果的按钮
- (id) initWithFrame:(CGRect)frame { if ((self = [super initWithFrame:frame])) { [self addObserver:self forKeyPath:@&highlighted& options:0 context:nil]; //增加对highlighted属性的观察 } }
-(void)dealloc { [self removeObserver:self forKeyPath:@&highlighted&];//移除对highlighted属性的观察 [super dealloc]; }
-(void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context { if ([keyPath isEqualToString:@&highlighted&]) { [self setNeedsDisplay];//当按钮被按下时,重绘按钮 } }
完整代码请点这里
Android_自定义控件样式
Android控件样式自定义是用定义在drawable文件夹下的XML文件实现,在布局文件中通过设置控件的background属性达到效果。
一、控件常见状态:在XML文件中用到了selector节点,selector可以理解为状态切换器,不同的状态下切换不同的样式,各种状态用Item节点表示,以下为一些常见的状态(注意:statelist中第一个匹配当前状态
Android自定义控件的使用
可能是一直都在做Web的富客户端开发的缘故吧,在接触Android之后,发现其控件实在惨不忍睹(不知道是否说得过于偏激),我所说的惨不忍睹的意思不是说控件难看,Android的控件非常漂亮,这是我们公司公认的,但是最大的缺点在于控件功能非常弱小。弱小得一个Radio只能放一个text,而没有value(key)可以存放。这就是为什么我说惨不忍睹的原因
android 自定义ScrollView实现反弹效果
首先还是一贯作风,先看一些案例:(微信界面)
玩过微信的朋友想必很熟悉,其实就是界面可以拖拽,会有反弹效果,看起来很炫酷.(总之比拖拽没反应的死板要好.) 下面我来一一讲解如何实现这样效果: 原理:自定义ScrollView对其Touch监听,对布
android自定义控件属性问题 在values目录下创建了attrs.xml &?xml version=&1.0& encoding=&utf-8&?& &resources&
&declare-styleable name=&PagerHeader&&
Android自定义EditText,实现分割输入内容效果
例如,输入一组25位的序列号,希望分成5组,每组5个数字。效果如下图。
Android中没有发现类似的空间,只好自己动手了。
1.首先自定义控件继承EditText,实现相应方法。
package com.example. import android.content.C impo
android评分条RatingBar自定义设置
RatingBar为评分条控件,默认效果为若干个绿色的星星,如果想将其换成其他自定义图片就要自定义它的style。首先是布局文件: &RatingBar android:id=&@+id/app_ratingbar& style=&@style/MyRatingBar& android:layout_
Android 工程混淆后无法找到自定义控件类的解决方案
Android 工程混淆后报出如下错误:
10-19 13:26:19.750: E/AndroidRuntime(13654): Caused by: android.view.InflateException: Binary XML file line #193: Error inflating
android 自定义 画板
package com. import android.content.C import android.graphics.B import android.graphics.C import android.graphics.C import android.graphics.Paint
android显示自定义view
自定义view public class LogoViewAndroid extends View{ [emailprotected] public void onDraw(Canvas canvas) {//draw some thing}
activity调用 public class Co
Android ListView 选中效果 自定义
你是不是也像我一样碰到这样的问题呢?现在我就带着大家一起来解决,我也是通过网上一些资料和自已调试源码得到的答案。
现在我给大家说下我的跟踪步骤:
1)在网上找到资料说默认的选中效果是也个drawable目录在源码的:fram
Android 自定义progressDialog实现
[size=large] 我们在项目中经常会遇到这样一个应用场景:执行某个耗时操作时,为了安抚用户等待的烦躁心情我们一般会使用进度条之类的空间,在android中让大家最 容易想到的就是progressbar或者progressDialog,区别在于前者是一个控件,后者是对话框。由于一些需求在弹出进度条时不希望用户 能够操作其他
[zz]Android自定义View:初探实例
本文来自:/ufocdy/archive//2048958.html
Android自定义View实现很简单 继承View,重写构造函数、onDraw,(onMeasure)等函数。 如果自定义的View需要有自定义的属性,需要在values下建立attrs.xml。在其
android自定义带下划线EditText
最近做项目,需要用到带下划线的EditText,通过学习Android提供的示例Notepad,对其进行小小的改动,解决文字压线的问题,但是光标压线的问题没有解决,希望以后能够解决,效果和代码如下: 效果图:
public class UnderlineEditText extends EditText { private sta
android 自定义ViewGroup和对view进行切图动画实现滑动菜单SlidingMenu
示意图就不展示了,和上一节的一样,滑动菜单SlidingMenu效果如何大家都比较熟悉,在这里我简单说明一下用自定义ViewGroup来实现.
实现方法:我们自定义一个ViewGroup实现左右滑动,第一屏隐藏,第二屏显示.
Android 如何自定义共享库
一、开发者的难言之隐---讨厌的集成
在Android 实际开发过程中,每个供应商都会有自己专有的开发库如驱动程序、常用API的封装等。如何把这些用于开发的库无缝地集成到Android 框架中成为了开发者最为头痛的事,每添加一个新的库就需要把Android 框架翻个遍,寻找合适的地方放置自己的代码,到最后把 Android 的源码改得支
android 可自定义大小和位置的Dialog
我实现了一个可自定义大小和位置的Dialog:CustDialog,其父类为AlertDialog 使用示例:
TestDialog t = newTestDialog(AndroidTestActivity.this,R.s
Android自定义组件2转载
原创作品,允许转载,转载时请务必以超链接形式标明文章 原始出处 、作者信息和本声明。否则将追究法律责任。http://vaero./734
&!--正文 begin--&
Android自定义组件(一)
android 自定义组件 在 graphical layout 不显示的问题
经过各种分析,结果发现这样可以解决:
在你的自定义控件的构造函数,onLayout(),onFinishInflate()的super方法后面加上如下代码,即可在Graphical Layout界面下看到,但是不会显示控件的内容,不过你可以只在你报错的地方加上这个代码:
if (isInEditMode())
android 自定义对话框,并记录选择项状态
android 自定义对话框,并记录选择项状态
Android 之ExpandableListView 完全仿QQ好友列表,自定义ExpandableListView
&?xml version=&1.0& encoding=&utf-8&?& &LinearLayout xmlns:android=&http://schemas.an
求助:在自定义的View上如何边输入边显示字符串 在自定义的View上(比如绘图的View,就像在画布上任意位置输入文字,画图软件里面常有的),我知道可以用
Canvas.drawText来显示字符串,但是字符串输入呢,用监听keyDown?
但是我目前只能在Activity里面监听到KeyDown 在View里面监听不到,
目前有两个疑问,希望高手能帮忙解决:
1.是否能自定义一个控件x
Android自定义进度条颜色
先看效果图:
老是提些各种需求问题,我觉得系统默认的颜色挺好的,但是Pk不过,谁叫我们不是需求人员呢,改吧! 这个没法了只能看源码了,还好下载了源码, sources\base\core\res\res\ 下应有尽有,修改进度条颜色只能找progress ,因为是改变样式,首先找styles.xml 找到xml后,进去找到:
关于AlertDialog.Builder弹出自定义布局窗口问题 虽然可以弹出自定义布局的窗口,但是我想在窗口弹出前,对布局的数据进行初始化,就是把想要的数据加载到布局上
默认弹出来的是布局前一丝不变的窗口,这不是我想要的效果
LayoutInflaterinflater=getLayoutInflater();
Viewlayout=infl
android自定义通知的问题
通过加载静态的xml,可以弹出通知.. 如果现在我的xml是动态生成的呢,该怎么做..
public class Notice {
private static final int notification_ID = 0x6238;
private static final int layout_id = 0x;
private stat
Android提高十八篇之自定义Menu(TabMenu) [转]
本文来自http://blog.csdn.net/hellogv/ ,引用必须注明出处!
用过UCWEB-Android版的人都应该对其特殊的menu有印象,把menu做成Tab-Menu(支持分页的Menu),可以容纳比Android传统的menu更丰富的内容(Android的menu超过6项则缩略在[更多]里),本文参考网
android自定义滑动启动和关闭按钮
在很多时候我们看到在iphone手机应用中都有滑动开启和关闭这个功能,在android40以下的版本中且没有这个功能,但是android手机在使用的多是4.0以下的系统,所以为了满足需求,我们自己设计自定的滑动开启和关闭按钮。
第一步:创建一个打开关闭的状态接口函数OnChangedListener主要创建一个打
Android开发中自定义View设定到FrameLayout布局中实现多组件显示
文章转自沈大海老师csdn博客:http://blog.csdn.net/sdhjob/ 在Android开发中,如果我们想自定义View视图组件,并实现在FrameLayout布局中多个组件的同时显示呢?
举例来说想在自定义的View上面显示Button 等View组件需要完成如下任务
1.在自定义View
android 单选按钮 RadioButton 自定义图片左边距
很多时候,我们在使用安卓单选按钮的时候,并不会使用安卓自带的单选按钮。 当我们自己设定一个单选图片的时候,一般都会设置 paddingLeft 让文字接在单选按钮图片的右边。 这样因为分辨率不同,会出现文字便宜不正常,解决方法就是:我们需要动态计算paddingLeft,代码如下:
自定义的一个Dialog,标题上两个圆角怎么设置 自定义的布局,在shape.xml里的代码是
&?xmlversion=&1.0&encoding=&UTF-8&?&
&shapexmlns:android=&/
(2)——— android 1.6 launcher研究之自定义ViewGroup
(2)——— android 1.6 launcher研究之自定义ViewGroup
1、用xml来作为ViewGroup里面的View 参考:/thread-.html
MyViewGroup.j
使用自定义的SimpleAdapter,内容由数据库读取生成的listiew如何更新 如题,请问如何更新。
SimpleCursorAdapter有changeCursor可以刷新,SimpleAdapter该如何做呢?单单的adapter.notifyDataSetChanged()没有效果。谢谢!
------解决方案--------------------
要不再试试重置adapte
android 录像,摄影自定义保存的文件名称
public class TestActivity extends Activity {
public static final int NONE = 0;
public static final int REQUEST_C
listview 自定义布局 里的 按钮事件如何判断有重复的数据
我目前开发的一个小项目,在开发过程中采用了listview自定义布局里的按钮事件,来给listview增加数据,现在的问题是如何判断数据已经增加过了?(如何判断有重复的数据?)
------最佳解决方案-------------------- List&
完全自定义Android对话框AlertDialog的实现
Android本身封装的AlertDialog.Builder很方便易用,但如果想要自定义弹出对话框的风格,如标题字体背景元素间隔之类的,那就比较困难了。 最近我就遇到了这个问题,一个工程的界面风格全改成蓝白色了,自然客户希望对话框也是蓝白色的,同时字体也有变化。但安卓自带对话框默认是黑白的,不同手机厂商定制的ROM显示的对话框各不相同
自定义ViewGroup中不能正确显示 其它的viewGroup 问题描述:
小弟写了一个MyViewGroup(extendsViewGroup),在MyViewGroup中可以正确显示childview都是widget类型的(例如Button,ImageButton),但不能正确显示其它的ViewGroup比如系统的RelativeLayout。我在xml中Rela
百度应用 android客户端(一)自定义导航栏
title布局activity_main_title.xml
&?xml version=&1.0& encoding=&utf-8&?& &RelativeLayout xmlns:android=&http://schemas.android.
android怎样自定义Intent选择界面的标题 可以使用 Intent.createChooser() 的方法来创建 Intent,并传入想要的 Sting 作为标题。
以wallpaper 选择框为例,当在Launcher workspace的空白区域上长按,会弹出wallpaper的选择框,选择框的标题为”Choose wallpaper from”,如下:
Android应用程序添加自定义的property属性 这是因为Android只有root, system, media用户才有权限写property, 而普通APP的用户ID是APP_XXX, 所以需要提升权限. 前提一定要基于Android源码来编译, 不能基于SDK编译
Android.mk里面要添加
LOCAL_CERTIFICATE := platform
Android提高第十八篇之自定义PopupWindow实现的Menu(TabMenu)
http://blog.csdn.net/hellogv/archive//6168439.aspx 用过UCWEB-Android版的人都应该对其特殊的menu有印象,把menu做成Tab-Menu(支持分页的Menu),可以容纳比Android传统的menu更丰富的内容(Androi
Android 防止控件被重复点击
在开发中经常会遇到这样的情况,一个按钮点击后会弹出Toast或者Dialog,如果快速重复地点击,则Toast则会重复地出现. 而我们想要的效果是一定时间内的点击只生效一次,或者说这种快速且重复的点击为无效点击.
解决的思路如下: 1. 需要定义一个全局变量 lastClickTime, 用来记录最后点击的时间. 2. 每次点击前需记录下UIButton的图文妙用和子控件的优先显示,uibutton图文-android100学习网
记录下UIButton的图文妙用和子控件的优先显示,uibutton图文
记录下UIButton的图文妙用和子控件的优先显示,uibutton图文   UIButton的用处特别多,这里只记录下把按钮应用在图文显示的场景,和需要把图片作为按钮的背景图片显示场景; 另外...
记录下UIButton的图文妙用和子控件的优先显示,uibutton图文
  UIButton的用处特别多,这里只记录下把按钮应用在图文显示的场景,和需要把图片作为按钮的背景图片显示场景;
另外记录下在父控件的子控件优先显示方法(控件置于最前面和置于最后面)。
先上效果图:
1、当在某个地方既需要显示图片,还需要显示文字,另外还要有点击功能的时候,这时按钮是个很好的选择。
  按钮中的图片和文字的距离可以自由调整,图片的也可以上下左右翻转。日常项目中像这些场景都是很容易碰到的。
  按钮图文设置、图文位置移动、按钮中图片翻转示例代码:
/** 测试图文并茂的按钮,图文移动 */
- (void)addMoveImgAndTextButton{
//1、创建一个按钮:30x50
UIButton *iconBtn = [[UIButton alloc] initWithFrame:CGRectMake(10, 100, 150, 80)];
[iconBtn setTitle:@"我的好友" forState:UIControlStateNormal];
[iconBtn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
[iconBtn setImage:[UIImage imageNamed:@"pointer"] forState:UIControlStateNormal];
iconBtn.layer.borderColor = [UIColor redColor].CGC
//边框颜色
iconBtn.layer.borderWidth = 1;
//边框宽度
iconBtn.titleLabel.backgroundColor = [UIColor greenColor]; //文字颜色
iconBtn.imageView.backgroundColor = [UIColor blackColor]; //图片颜色
[iconBtn addTarget:self action:@selector(clickButton:) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:iconBtn];
self.iconBtn = iconB
//2、移动iconBtn按钮图片和文字
UIButton *btn = [[UIButton alloc] initWithFrame:CGRectMake(170, 100, 120, 45)];
[btn setTitle:@"图右移字左移" forState:UIControlStateNormal];
btn.titleLabel.numberOfLines = 0;
[btn setBackgroundColor:[UIColor blackColor]];
[btn addTarget:self action:@selector(changeBtnFrame:) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:btn];
//3、移动iconBtn按钮图片和文字
UIButton *btn2 = [[UIButton alloc] initWithFrame:CGRectMake(170, 150, 120, 45)];
[btn2 setTitle:@"字右移图左移" forState:UIControlStateNormal];
btn2.titleLabel.numberOfLines = 0;
[btn2 setBackgroundColor:[UIColor blackColor]];
[btn2 addTarget:self action:@selector(changeBtnFrame2:) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:btn2];
UIView *lineView = [[UIView alloc] initWithFrame:CGRectMake(0, 210, 500, 1)];
lineView.backgroundColor = [UIColor grayColor];
[self.view addSubview:lineView];
/** 点击按钮使图片位置翻转 */
- (void)clickButton:(UIButton *)sender{
sender.imageView.transform = CGAffineTransformRotate(sender.imageView.transform, M_PI);
/** 移动图片和文字位置 */
- (void)changeBtnFrame:(UIButton *)sender{
UIEdgeInsets edge = self.iconBtn.imageEdgeI
CGFloat changeNum = 10;
self.iconBtn.imageEdgeInsets = UIEdgeInsetsMake(0, edge.left + changeNum, 0, -(edge.left + changeNum));
self.iconBtn.titleEdgeInsets = UIEdgeInsetsMake(0, -(edge.left + changeNum), 0, edge.left + changeNum);
NSLog(@"edge.left: %f, edge.right: %f", edge.left, edge.right);
/** 反方向移动图片和文字位置 */
- (void)changeBtnFrame2:(UIButton *)sender{
UIEdgeInsets edge = self.iconBtn.imageEdgeI
CGFloat changeNum = 10;
self.iconBtn.imageEdgeInsets = UIEdgeInsetsMake(0, edge.left - changeNum, 0, -(edge.left - changeNum));
self.iconBtn.titleEdgeInsets = UIEdgeInsetsMake(0, -(edge.left - changeNum), 0, edge.left - changeNum);
NSLog(@"...edge.left: %f, edge.right: %f", edge.left, edge.right);
2、有时候需要给按钮设置背景图片,一般UI给个图片,然后我们自己对图片进行处理,让背景图片自适应按钮展示,矩形圆角。
  但是有时候,产品要求显示的按钮左右必须是圆形的,这时候虽然可以让ui切个适配的图片做背景,其实针对如果是背景图片是纯色的话,我们可以利用
控件的layer.masksToBounds, 和layer.cornerRadius属性来让按钮或者其他控件左右两边都是圆形的。
下面写了五个橙色背景的按钮作比较:背景图片和按钮尺寸匹配的、背景图片和按钮尺寸或偏大或偏小的、处理背景图片让背景图片自适应按钮的、不用背景图片使用图层来设置按钮左右圆形的:
/** 测试给按钮设置背景图片 */
- (void)addBackgroundImgButton{
//4、96x25 按钮设置背景图片,颜色rgb(255,145,0)
UIImage *img = [UIImage imageNamed:@"btn_bg"];
UIButton *clickBtn = [[UIButton alloc] initWithFrame:CGRectMake(10, 240, 96, 25)];
[clickBtn setBackgroundImage:img forState:UIControlStateNormal];
[clickBtn setTitle:@"click Me" forState:UIControlStateNormal];
[self.view addSubview:clickBtn];
//4.2 给按钮设置背景图片, 按钮图片不适配
UIButton *clickBtn2 = [[UIButton alloc] initWithFrame:CGRectMake(120, 220, 120, 50)];
[clickBtn2 setBackgroundImage:img forState:UIControlStateNormal];
[clickBtn2 setTitle:@"click Me" forState:UIControlStateNormal];
[self.view addSubview:clickBtn2];
//4.3 给按钮设置背景图片,按钮和图片不适配
UIButton *clickBtn3 = [[UIButton alloc] initWithFrame:CGRectMake(260, 240, 80, 15)];
[clickBtn3 setBackgroundImage:img forState:UIControlStateNormal];
[clickBtn3 setTitle:@"click Me" forState:UIControlStateNormal];
[self.view addSubview:clickBtn3];
//4.4 处理背景图片,让背景图片自适应按钮
NSLog(@"img.size: %@", NSStringFromCGSize(img.size));
UIImage *newImg = [img stretchableImageWithLeftCapWidth:img.size.width/2 topCapHeight:img.size.height/2];
NSLog(@"newImg.size: %@", NSStringFromCGSize(newImg.size));
UIButton *clickBtn4 = [[UIButton alloc] initWithFrame:CGRectMake(10, 300, 150, 60)];
[clickBtn4 setBackgroundImage:newImg forState:UIControlStateNormal];
[clickBtn4 setTitle:@"click Me" forState:UIControlStateNormal];
[self.view addSubview:clickBtn4];
//4.5 按钮不使用背景图片,设置背景颜色当做有背景图片
UIButton *clickBtn5 = [[UIButton alloc] initWithFrame:CGRectMake(180, 300, 150, 60)];
[clickBtn5 setTitle:@"click Me" forState:UIControlStateNormal];
clickBtn5.layer.masksToBounds = YES;
clickBtn5.layer.cornerRadius = 30;
clickBtn5.backgroundColor = [UIColor colorWithRed:255/255.f green:145/255.f blue:0 alpha:1];
[self.view addSubview:clickBtn5];
UIView *lineView = [[UIView alloc] initWithFrame:CGRectMake(0, 380, 500, 1)];
lineView.backgroundColor = [UIColor grayColor];
[self.view addSubview:lineView];
3、在有些场景下,需要控制控件的优先显示或者置后显示,需要用到方法
- (void)bringSubviewToFront:(UIView *)
// 将子控件view显示在父控件的所有子控件的最前面
- (void)sendSubviewToBack:(UIView *)
//将子控件view显示在父控件的所有子控件的最后面
示例代码:
/** 测试子控件的优先显示(置前和置后) */
- (void)testSubControlShowFront{
//1、红色view
UIView *redView = [[UIView alloc] initWithFrame:CGRectMake(10, 420, 200, 200)];
redView.backgroundColor = [UIColor redColor];
redView.tag = 11;
[self.view addSubview:redView];
//2、黑色view
UIView *blackView = [[UIView alloc] initWithFrame:CGRectMake(30, 400, 200, 200)];
blackView.backgroundColor = [UIColor blackColor];
blackView.tag = 12;
[self.view addSubview:blackView];
//3、紫色view
UIView *purpleView = [[UIView alloc] initWithFrame:CGRectMake(50, 440, 200, 200)];
purpleView.backgroundColor = [UIColor purpleColor];
purpleView.tag = 13;
[self.view addSubview:purpleView];
//添加操作按钮
UIButton *operatorBtn = [[UIButton alloc] initWithFrame:CGRectMake(280, 400, 100, 30)];
[operatorBtn setTitle:@"红色置前" forState:UIControlStateNormal];
operatorBtn.tag = 1;
operatorBtn.backgroundColor = [UIColor blackColor];
[operatorBtn addTarget:self action:@selector(changeViewToFrontShow:) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:operatorBtn];
UIButton *operatorBtn2 = [[UIButton alloc] initWithFrame:CGRectMake(280, 450, 100, 30)];
[operatorBtn2 setTitle:@"黑色置前" forState:UIControlStateNormal];
operatorBtn2.tag = 2;
operatorBtn2.backgroundColor = [UIColor blackColor];
[operatorBtn2 addTarget:self action:@selector(changeViewToFrontShow:) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:operatorBtn2];
UIButton *operatorBtn3 = [[UIButton alloc] initWithFrame:CGRectMake(280, 500, 100, 30)];
[operatorBtn3 setTitle:@"紫色置前" forState:UIControlStateNormal];
operatorBtn3.tag = 3;
operatorBtn3.backgroundColor = [UIColor blackColor];
[operatorBtn3 addTarget:self action:@selector(changeViewToFrontShow:) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:operatorBtn3];
UIButton *operatorBtn4 = [[UIButton alloc] initWithFrame:CGRectMake(280, 550, 100, 30)];
[operatorBtn4 setTitle:@"紫色置后" forState:UIControlStateNormal];
operatorBtn4.tag = 4;
operatorBtn4.backgroundColor = [UIColor redColor];
[operatorBtn4 addTarget:self action:@selector(changeViewToFrontShow:) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:operatorBtn4];
/** 操作按钮,切换view置前显示 */
- (void)changeViewToFrontShow:(UIButton *)sender{
if (sender.tag == 1){
//红色置前
UIView *redView = [self.view viewWithTag:11];
//将子控件redView在父控件view的所有子控件的最前面显示
[self.view bringSubviewToFront:redView];
else if (sender.tag == 2){
//黑色置前
UIView *blackView = [self.view viewWithTag:12]; //获取黑色子控件
//将子控件blackView在父控件view的所有子控件的最前面显示
[self.view bringSubviewToFront:blackView];
else if (sender.tag == 3){
//紫色置前
UIView *purpleView = [self.view viewWithTag:13]; //获取紫色子控件
//将子控件purpleView在父控件view的所有子控件的最前面显示
[self.view bringSubviewToFront:purpleView];
else if (sender.tag == 4){
//紫色置后
UIView *purpleView = [self.view viewWithTag:13]; //获取紫色子控件
//将子控件purpleView在父控件view的所有子控件的最后面显示
[self.view sendSubviewToBack:purpleView];
------------------------------------------------------------------------------
TestButtonVC.m
tan_iosTwo
Created by PX_Mac on 16/10/16.
#import "TestButtonVC.h"
@interface TestButtonVC ()
@property (nonatomic, weak) UIButton *iconB //带文字和图片的按钮
@implementation TestButtonVC
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view.
[self addMoveImgAndTextButton]; //添加图文并茂的按钮,测试按钮上的图文移动
[self addBackgroundImgButton]; //添加设置背景图片的按钮
[self testSubControlShowFront]; //测试子控件的优先或置后显示
/** 测试图文并茂的按钮,图文移动 */
- (void)addMoveImgAndTextButton{
//1、创建一个按钮:30x50
UIButton *iconBtn = [[UIButton alloc] initWithFrame:CGRectMake(10, 100, 150, 80)];
[iconBtn setTitle:@"我的好友" forState:UIControlStateNormal];
[iconBtn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
[iconBtn setImage:[UIImage imageNamed:@"pointer"] forState:UIControlStateNormal];
iconBtn.layer.borderColor = [UIColor redColor].CGC
//边框颜色
iconBtn.layer.borderWidth = 1;
//边框宽度
iconBtn.titleLabel.backgroundColor = [UIColor greenColor]; //文字颜色
iconBtn.imageView.backgroundColor = [UIColor blackColor]; //图片颜色
[iconBtn addTarget:self action:@selector(clickButton:) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:iconBtn];
self.iconBtn = iconB
//2、移动iconBtn按钮图片和文字
UIButton *btn = [[UIButton alloc] initWithFrame:CGRectMake(170, 100, 120, 45)];
[btn setTitle:@"图右移字左移" forState:UIControlStateNormal];
btn.titleLabel.numberOfLines = 0;
[btn setBackgroundColor:[UIColor blackColor]];
[btn addTarget:self action:@selector(changeBtnFrame:) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:btn];
//3、移动iconBtn按钮图片和文字
UIButton *btn2 = [[UIButton alloc] initWithFrame:CGRectMake(170, 150, 120, 45)];
[btn2 setTitle:@"字右移图左移" forState:UIControlStateNormal];
btn2.titleLabel.numberOfLines = 0;
[btn2 setBackgroundColor:[UIColor blackColor]];
[btn2 addTarget:self action:@selector(changeBtnFrame2:) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:btn2];
UIView *lineView = [[UIView alloc] initWithFrame:CGRectMake(0, 210, 500, 1)];
lineView.backgroundColor = [UIColor grayColor];
[self.view addSubview:lineView];
/** 点击按钮使图片位置翻转 */
- (void)clickButton:(UIButton *)sender{
sender.imageView.transform = CGAffineTransformRotate(sender.imageView.transform, M_PI);
/** 移动图片和文字位置 */
- (void)changeBtnFrame:(UIButton *)sender{
UIEdgeInsets edge = self.iconBtn.imageEdgeI
CGFloat changeNum = 10;
self.iconBtn.imageEdgeInsets = UIEdgeInsetsMake(0, edge.left + changeNum, 0, -(edge.left + changeNum));
self.iconBtn.titleEdgeInsets = UIEdgeInsetsMake(0, -(edge.left + changeNum), 0, edge.left + changeNum);
NSLog(@"edge.left: %f, edge.right: %f", edge.left, edge.right);
/** 反方向移动图片和文字位置 */
- (void)changeBtnFrame2:(UIButton *)sender{
UIEdgeInsets edge = self.iconBtn.imageEdgeI
CGFloat changeNum = 10;
self.iconBtn.imageEdgeInsets = UIEdgeInsetsMake(0, edge.left - changeNum, 0, -(edge.left - changeNum));
self.iconBtn.titleEdgeInsets = UIEdgeInsetsMake(0, -(edge.left - changeNum), 0, edge.left - changeNum);
NSLog(@"...edge.left: %f, edge.right: %f", edge.left, edge.right);
/** 测试给按钮设置背景图片 */
- (void)addBackgroundImgButton{
//4、96x25 按钮设置背景图片,颜色rgb(255,145,0)
UIImage *img = [UIImage imageNamed:@"btn_bg"];
UIButton *clickBtn = [[UIButton alloc] initWithFrame:CGRectMake(10, 240, 96, 25)];
[clickBtn setBackgroundImage:img forState:UIControlStateNormal];
[clickBtn setTitle:@"click Me" forState:UIControlStateNormal];
[self.view addSubview:clickBtn];
//4.2 给按钮设置背景图片, 按钮图片不适配
UIButton *clickBtn2 = [[UIButton alloc] initWithFrame:CGRectMake(120, 220, 120, 50)];
[clickBtn2 setBackgroundImage:img forState:UIControlStateNormal];
[clickBtn2 setTitle:@"click Me" forState:UIControlStateNormal];
[self.view addSubview:clickBtn2];
//4.3 给按钮设置背景图片,按钮和图片不适配
UIButton *clickBtn3 = [[UIButton alloc] initWithFrame:CGRectMake(260, 240, 80, 15)];
[clickBtn3 setBackgroundImage:img forState:UIControlStateNormal];
[clickBtn3 setTitle:@"click Me" forState:UIControlStateNormal];
[self.view addSubview:clickBtn3];
//4.4 处理背景图片,让背景图片自适应按钮
NSLog(@"img.size: %@", NSStringFromCGSize(img.size));
UIImage *newImg = [img stretchableImageWithLeftCapWidth:img.size.width/2 topCapHeight:img.size.height/2];
NSLog(@"newImg.size: %@", NSStringFromCGSize(newImg.size));
UIButton *clickBtn4 = [[UIButton alloc] initWithFrame:CGRectMake(10, 300, 150, 60)];
[clickBtn4 setBackgroundImage:newImg forState:UIControlStateNormal];
[clickBtn4 setTitle:@"click Me" forState:UIControlStateNormal];
[self.view addSubview:clickBtn4];
//4.5 按钮不使用背景图片,设置背景颜色当做有背景图片
UIButton *clickBtn5 = [[UIButton alloc] initWithFrame:CGRectMake(180, 300, 150, 60)];
[clickBtn5 setTitle:@"click Me" forState:UIControlStateNormal];
clickBtn5.layer.masksToBounds = YES;
clickBtn5.layer.cornerRadius = 30;
clickBtn5.backgroundColor = [UIColor colorWithRed:255/255.f green:145/255.f blue:0 alpha:1];
[self.view addSubview:clickBtn5];
UIView *lineView = [[UIView alloc] initWithFrame:CGRectMake(0, 380, 500, 1)];
lineView.backgroundColor = [UIColor grayColor];
[self.view addSubview:lineView];
/** 测试子控件的优先显示(置前和置后) */
- (void)testSubControlShowFront{
//1、红色view
UIView *redView = [[UIView alloc] initWithFrame:CGRectMake(10, 420, 200, 200)];
redView.backgroundColor = [UIColor redColor];
redView.tag = 11;
[self.view addSubview:redView];
//2、黑色view
UIView *blackView = [[UIView alloc] initWithFrame:CGRectMake(30, 400, 200, 200)];
blackView.backgroundColor = [UIColor blackColor];
blackView.tag = 12;
[self.view addSubview:blackView];
//3、紫色view
UIView *purpleView = [[UIView alloc] initWithFrame:CGRectMake(50, 440, 200, 200)];
purpleView.backgroundColor = [UIColor purpleColor];
purpleView.tag = 13;
[self.view addSubview:purpleView];
//添加操作按钮
UIButton *operatorBtn = [[UIButton alloc] initWithFrame:CGRectMake(280, 400, 100, 30)];
[operatorBtn setTitle:@"红色置前" forState:UIControlStateNormal];
operatorBtn.tag = 1;
operatorBtn.backgroundColor = [UIColor blackColor];
[operatorBtn addTarget:self action:@selector(changeViewToFrontShow:) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:operatorBtn];
UIButton *operatorBtn2 = [[UIButton alloc] initWithFrame:CGRectMake(280, 450, 100, 30)];
[operatorBtn2 setTitle:@"黑色置前" forState:UIControlStateNormal];
operatorBtn2.tag = 2;
operatorBtn2.backgroundColor = [UIColor blackColor];
[operatorBtn2 addTarget:self action:@selector(changeViewToFrontShow:) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:operatorBtn2];
UIButton *operatorBtn3 = [[UIButton alloc] initWithFrame:CGRectMake(280, 500, 100, 30)];
[operatorBtn3 setTitle:@"紫色置前" forState:UIControlStateNormal];
operatorBtn3.tag = 3;
operatorBtn3.backgroundColor = [UIColor blackColor];
[operatorBtn3 addTarget:self action:@selector(changeViewToFrontShow:) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:operatorBtn3];
UIButton *operatorBtn4 = [[UIButton alloc] initWithFrame:CGRectMake(280, 550, 100, 30)];
[operatorBtn4 setTitle:@"紫色置后" forState:UIControlStateNormal];
operatorBtn4.tag = 4;
operatorBtn4.backgroundColor = [UIColor redColor];
[operatorBtn4 addTarget:self action:@selector(changeViewToFrontShow:) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:operatorBtn4];
/** 操作按钮,切换view置前显示 */
- (void)changeViewToFrontShow:(UIButton *)sender{
if (sender.tag == 1){
//红色置前
UIView *redView = [self.view viewWithTag:11];
//将子控件redView在父控件view的所有子控件的最前面显示
[self.view bringSubviewToFront:redView];
else if (sender.tag == 2){
//黑色置前
UIView *blackView = [self.view viewWithTag:12]; //获取黑色子控件
//将子控件blackView在父控件view的所有子控件的最前面显示
[self.view bringSubviewToFront:blackView];
else if (sender.tag == 3){
//紫色置前
UIView *purpleView = [self.view viewWithTag:13]; //获取紫色子控件
//将子控件purpleView在父控件view的所有子控件的最前面显示
[self.view bringSubviewToFront:purpleView];
else if (sender.tag == 4){
//紫色置后
UIView *purpleView = [self.view viewWithTag:13]; //获取紫色子控件
//将子控件purpleView在父控件view的所有子控件的最后面显示
[self.view sendSubviewToBack:purpleView];
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
#pragma mark - Navigation
// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
// Get the new view controller using [segue destinationViewController].
// Pass the selected object to the new view controller.
原文链接:/tandaxia/p/5975729.html

我要回帖

更多关于 win7开机无限循环重启 的文章

 

随机推荐