神盾局特工第三季结局四季结局什么意思 神盾局特

37037人阅读
IOS实例学习笔记(70)
作者:朱克锋
转载请注明出处:http://blog.csdn.net/linux_zkf
IOS 按钮(button)用法与属性实例
- (void) toggleButton: (UIButton *) button
if (isOn = !isOn)
[button setTitle:@&On&
forState:UIControlStateNormal];
[button setTitle:@&On&
forState:UIControlStateHighlighted];
[button setBackgroundImage:baseGreen
forState:UIControlStateNormal];
[button setBackgroundImage:altGreen
forState:UIControlStateHighlighted];
[button setTitle:@&Off&
forState:UIControlStateNormal];
[button setTitle:@&Off&
forState:UIControlStateHighlighted];
[button setBackgroundImage:baseRed
forState:UIControlStateNormal];
[button setBackgroundImage:altRed
forState:UIControlStateHighlighted];
- (void) viewDidLoad
float capWidth =
baseGreen = [[[UIImage
imageNamed:@&green.png&]
stretchableImageWithLeftCapWidth:capWidth topCapHeight:0.0f]
baseRed = [[[UIImage
imageNamed:@&red.png&]
stretchableImageWithLeftCapWidth:capWidth topCapHeight:0.0f]
altGreen = [[[UIImage
imageNamed:@&green2.png&]
stretchableImageWithLeftCapWidth:capWidth topCapHeight:0.0f]
altRed = [[[UIImage
imageNamed:@&red2.png&]
stretchableImageWithLeftCapWidth:capWidth topCapHeight:0.0f]
UIButton *button = [UIButton
buttonWithType:UIButtonTypeCustom];
button.frame =
CGRectMake(0.0f, 0.0f,
300.0f, 233.0f);
button.center =
CGPointMake(160.0f, 140.0f);
// 设置aligment
button.contentVerticalAlignment =
UIControlContentVerticalAlignmentCenter;
button.contentHorizontalAlignment =
UIControlContentHorizontalAlignmentCenter;
//button.titleLabel.textAlignment =
UITextAlignmentCenter;
//设置title自适应对齐
button.titleLabel.lineBreakMode =
UILineBreakModeWordWrap;
// 设置颜色和字体
[button setTitleColor:[UIColor
whiteColor] forState:UIControlStateNormal];
[button setTitleColor:[UIColor
lightGrayColor] forState:UIControlStateHighlighted];
button.titleLabel.font = [UIFont
boldSystemFontOfSize:24.0f];
// 添加 action
[button addTarget:self
action:@selector(toggleButton:)
forControlEvents: UIControlEventTouchUpInside];
& & //设置title
& & [button setTitle:@&On&
forState:UIControlStateNormal];
& & [button setTitle:@&On&
forState:UIControlStateHighlighted];
& & //设置背景
& & [button setBackgroundImage:baseGreen
forState:UIControlStateNormal];
& & [button setBackgroundImage:altGreen
forState:UIControlStateHighlighted];
// 用于测试的BOOL
isOn = NO;
// 把button放入view
[self.view
addSubview:button];
参考知识库
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
访问:397234次
积分:4819
积分:4819
排名:第5181名
原创:136篇
评论:42条
(10)(1)(3)(2)(3)(9)(78)(17)(4)(10)ImageTextButton
查看次数:1859
下载次数:453
上传时间:
大小:49 B
ImageTextButton是继承于UIButton的按钮,包含图片和文字,有四种常见的布局类型,只需要简单地设置属性UIButtonTitleWithImageAlignment即可实现很常用的图文并排的按钮,容易拓展。以后大家就可以不用自定义view、image、title、button来实现这样一个效果了。
利用的方法也是UIButton本身的固有属性UIEdgeInsets,设置图片和文字的相对位置,以达到常用的图文并排的按钮效果。
使用方法:
在需要用到的地方:
#import "ImageTextButton.h"
@property (nonatomic, strong) ImageTextButton *imgTextB
2. 直接调用
self.imgTextButton = [[ImageTextButton alloc] initWithFrame:CGRectMake((self.view.frame.size.width - 150) / 2, 200, 150, 100)
image:[UIImage imageNamed:@"buttonImg.png"]
title:@"点我"];
self.imgTextButton.imgTextDistance = 10; // 可修改图片标题的间距,默认为5
self.imgTextButton.buttonTitleWithImageAlignment = UIButtonTitleWithImageAlignmentUp;
[self.imgTextButton addTarget:self action:@selector(changeValue:) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:self.imgTextButton];
您还没有登录!请或
下载过该代码的还下载了
本周热门下载
&2017 Chukong Technologies,Inc.
京公网安备89

我要回帖

更多关于 神盾局特工第三季结局 的文章

 

随机推荐