重庆分公司,新征程启航

为企业提供网站建设、域名注册、服务器等服务

ios开发ui工厂类,ios的ui设计

ios开发中怎么给uicollectionviewlayout布局类赋值

iOS 越来越人性化了,用户可以在设置-通用-辅助功能中动态调整字体大小了。你会发现所有 iOS 自带的APP的字体大小都变了,可惜我们开发的第三方APP依然是以前的字体。在 iOS 7 之后我们可以用 UIFont 的preferredFontForTextStyle: 类方法来指定一个样式,并让字体大小符合用户设定的字体大小。目前可供选择的有六种样式:

网站建设哪家好,找创新互联公司!专注于网页设计、网站建设、微信开发、微信小程序开发、集团企业网站建设等服务项目。为回馈新老客户创新互联还提供了阳东免费建站欢迎大家使用!

UIFontTextStyleHeadline UIFontTextStyleBody UIFontTextStyleSubheadline UIFontTextStyleFootnote UIFontTextStyleCaption1 UIFontTextStyleCaption2

iOS会根据样式的用途来合理调整字体。

问题来了,诸如字体大小这种“动态类型”,我们需要对其进行动态的UI调整,否则总是觉得我们的界面怪怪的:

我们想要让Cell 的高度随着字体大小而作出调整:

总之,还会有其他动态因素导致我们需要修改布局。

解决方案

UITableView

有三种策略可以调节Cell(或者是Header和Footer)的高度:

a.调节Height属性

b.通过委托方法tableView: heightForRowAtIndexPath:

c.Cell的“自排列”(self-sizing)

前两种策略都是我们所熟悉的,后面将介绍第三种策略。UITableViewCell 和 UICollectionViewCell 都支持 self-sizing。

在 iOS 7 中,UITableViewDelegate新增了三个方法来满足用户设定Cell、Header和Footer预计高度的方法:

- tableView:estimatedHeightForRowAtIndexPath: - tableView:estimatedHeightForHeaderInSection: - tableView:estimatedHeightForFooterInSection:

当然对应这三个方法 UITableView 也 estimatedRowHeight、estimatedSectionHeaderHeight 和 estimatedSectionFooterHeight 三个属性,局限性在于只能统一定义所有行和节的高度。

以 Cell 为例,iOS 会根据给出的预计高度来创建一个Cell,但等到真正要显示它的时候,iOS 8会在 self-sizing 计算得出新的 Size 并调整 table 的 contentSize 后,将 Cell 绘制显示出来。关键在于如何得出 Cell 新的 Size,iOS提供了两种方法:

自动布局

这个两年前推出的神器虽然在一开始表现不佳,但随着 Xcode 的越来越给力,在iOS7中自动布局俨然成了默认勾选的选项,通过设定一系列约束来使得我们的UI能够适应各种尺寸的屏幕。如果你有使用约束的经验,想必已经有了解决思路:向 Cell 的 contentView 添加约束。iOS 会先调用 UIView 的 systemLayoutSizeFittingSize: 方法来根据约束计算新的Size,如果你没实现约束,systemLayoutSizeFittingSize: 会接着调用sizeThatFits:方法。

人工代码

我们可以重写sizeThatFits:方法来自己定义新的Size,这样我们就不必学习约束相关的知识了。

下面我给出了一个用 Swift 语言写的 Demo-HardChoice ,使用自动布局来调整UITableViewCell的高度。我通过实现一个UITableViewCell的子类DynamicCell来实现自动布局,你可以再GitHub上下载源码:

import UIKit class DynamicCell: UITableViewCell { required init(coder: NSCoder) { super.init(coder: coder) if textLabel != nil { textLabel.font = UIFont.preferredFontForTextStyle(UIFontTextStyleHeadline) textLabel.numberOfLines = 0 } if detailTextLabel != nil { detailTextLabel.font = UIFont.preferredFontForTextStyle(UIFontTextStyleBody) detailTextLabel.numberOfLines = 0 } } override func constraints() - [AnyObject] { var constraints = [AnyObject]() if textLabel != nil { constraints.extend(constraintsForView(textLabel)) } if detailTextLabel != nil { constraints.extend(constraintsForView(detailTextLabel)) } constraints.append(NSLayoutConstraint(item: contentView, attribute: NSLayoutAttribute.Height, relatedBy: NSLayoutRelation.GreaterThanOrEqual, toItem: contentView, attribute: NSLayoutAttribute.Height, multiplier: 0, constant: 44)) contentView.addConstraints(constraints) return constraints } func constraintsForView(view:UIView) - [AnyObject]{ var constraints = [NSLayoutConstraint]() constraints.append(NSLayoutConstraint(item: view, attribute: NSLayoutAttribute.FirstBaseline, relatedBy: NSLayoutRelation.Equal, toItem: contentView, attribute: NSLayoutAttribute.Top, multiplier: 1.8, constant: 30.0)) constraints.append(NSLayoutConstraint(item: contentView, attribute: NSLayoutAttribute.Bottom, relatedBy: NSLayoutRelation.GreaterThanOrEqual, toItem: view, attribute: NSLayoutAttribute.Baseline, multiplier: 1.3, constant: 8)) return constraints } }

上面的代码需要注意的是,Objective-C中的类在Swift中都可以被当做AnyObject,这在类型兼容问题上很管用。

别忘了在相应的 UITableViewController 中的 viewDidLoad 方法中加上:

self.tableView.estimatedRowHeight = 44

自适应效果如下:

UICollectionView

UITableView 和 UICollectionView 都是 data-source 和 delegate 驱动的。UICollectionView 在此之上进行了进一步抽象。它将其子视图的位置,大小和外观的控制权委托给一个单独的布局对象。通过提供一个自定义布局对象,你几乎可以实现任何你能想象到的布局。布局继承自 UICollectionViewLayout 抽象基类。iOS 6 中以 UICollectionViewFlowLayout 类的形式提出了一个具体的布局实现。在 UICollectionViewFlowLayout 中,self-sizing 同样适用:

采用self-sizing后:

UICollectionView 实现 self-sizing 不仅可以通过在 Cell 的 contentView 上加约束和重写 sizeThatFits: 方法,也能在 Cell 层面(以前都是在 contentSize 上进行 self-sizing)上做文章:重写 UICollectionReusableView 的preferredLayoutAttributesFittingAttributes: 方法来在 self-sizing 计算出 Size 之后再修改,这样就达到了对Cell布局属性(UICollectionViewLayoutAttributes)的全面控制。

PS:preferredLayoutAttributesFittingAttributes: 方法默认调整Size属性来适应 self-sizing Cell,所以重写的时候需要先调用父类方法,再在返回的 UICollectionViewLayoutAttributes 对象上做你想要做的修改。

由此我们从最经典的 UICollectionViewLayout 强制计算属性(还记得 UICollectionViewLayoutAttributes 的一系列工厂方法么?)到使用 self-sizing 来根据我们需求调整属性中的Size,再到重写UICollectionReusableView(UICollectionViewCell也是继承于它)的 preferredLayoutAttributesFittingAttributes: 方法来从Cell层面对所有属性进行修改:

下面来说说如何在 UICollectionViewFlowLayout 实现 self-sizing:

首先,UICollectionViewFlowLayout 增加了estimatedItemSize 属性,这与 UITableView 中的 ”estimated...Height“ 很像(注意我用省略号囊括那三种属性),但毕竟 UICollectionView 中的 Item 都需要约束 Height 和 Width的,所以它是个 CGSIze,除了这点它与 UITableView 中的”estimated...Height“用法没区别。

其...没有其次,在 UICollectionView 中实现 self-sizing,只需给 estimatedItemSize 属性赋值(不能是 CGSizeZero ),一行代码足矣。

InvalidationContext

假如设备屏幕旋转,或者需要展示一些其妙的效果(比如 CoverFlow ),我们需要将当前的布局失效,并重新计算布局。当然每次计算都有一定的开销,所以我们应该谨慎的仅在我们需要的时候调用 invalidateLayout 方法来让布局失效。

在 iOS 6 时代,有的人会“聪明地”这样做:

- (BOOL)shouldInvalidateLayoutForBoundsChange:(CGRect)newBounds { CGRect oldBounds = self.collectionView.bounds; if (CGRectGetWidth(newBounds) != CGRectGetWidth(oldBounds)) { return YES; } return NO; }

而 iOS 7 新加入的 UICollectionViewLayoutInvalidationContext 类声明了在布局失效时布局的哪些部分需要被更新。当数据源变更时,invalidateEverything 和 invalidateDataSourceCounts 这两个只读 Bool 属性标记了UICollectionView 数据源“全部过期失效”和“Section和Item数量失效”,UICollectionView会将它们自动设定并提供给你。

你可以调用invalidateLayoutWithContext:方法并传入一个UICollectionViewLayoutInvalidationContext对象,这能优化布局的更新效率。

当你自定义一个 UICollectionViewLayout 子类时,你可以调用 invalidationContextClass 方法来返回一个你定义的 UICollectionViewLayoutInvalidationContext 的子类,这样你的 Layout 子类在失效时会使用你自定义的InvalidationContext 子类来优化更新布局。

你还可以重写 invalidationContextForBoundsChange: 方法,在实现自定义 Layout 时通过重写这个方法返回一个 InvalidationContext 对象。

综上所述都是 iOS 7 中新加入的内容,并且还可以应用在 UICollectionViewFlowLayout 中。在 iOS 8 中,UICollectionViewLayoutInvalidationContext 也被用在self-sizing cell上。

iOS8 中 UICollectionViewLayoutInvalidationContext 新加入了三个方法使得我们可以更加细致精密地使某一行某一节Item(Cell)、Supplementary View 或 Decoration View 失效:

invalidateItemsAtIndexPaths: invalidateSupplementaryElementsOfKind:atIndexPaths: invalidateDecorationElementsOfKind:atIndexPaths:

对应着添加了三个只读数组属性来标记上面那三种组件:

invalidatedItemIndexPaths invalidatedSupplementaryIndexPaths invalidatedDecorationIndexPaths

iOS自带的照片应用会将每一节照片的信息(时间、地点)停留显示在最顶部,实现这种将 Header 粘在顶端的功能其实就是将那个 Index 的 Supplementary View 失效,就这么简单。

UICollectionViewLayoutInvalidationContext 新加入的 contentOffsetAdjustment 和 contentSizeAdjustment 属性可以让我们更新 CollectionView 的 content 的位移和尺寸。

此外 UICollectionViewLayout 还加入了一对儿方法来帮助我们使用self-sizing:

shouldInvalidateLayoutForPreferredLayoutAttributes:withOriginalAttributes: invalidationContextForPreferredLayoutAttributes:withOriginalAttributes:

当一个self-sizing Cell发生属性发生变化时,第一个方法会被调用,它询问是否应该更新布局(即原布局失效),默认为NO;而第二个方法更细化的指明了哪些属性应该更新,需要调用父类的方法获得一个InvalidationContext 对象,然后对其做一些你想要的修改,最后返回。

试想,如果在你自定义的布局中,一个Cell的Size因为某种原因发生了变化(比如由于字体大小变化),其他的Cell会由于 self-sizing 而位置发生变化,你需要实现上面两个方法来让指定的Cell更新布局中的部分属性;别忘了整个 CollectionView 的 contentSize 和 contentOffset 因此也会发生变化,你需要给 contentOffsetAdjustment 和 contentSizeAdjustment 属性赋值。

ios开发之uitableview优化机制有哪些

iOS开发UI篇—UITableviewcell的性能问题

一、UITableviewcell的一些介绍

UITableView的每一行都是一个UITableViewCell,通过dataSource的 tableView:cellForRowAtIndexPath:方法来初始化每⼀行

UITableViewCell内部有个默认的子视图:contentView,contentView是UITableViewCell所显示内容的父视图,可显示一些辅助指示视图

辅助指示视图的作⽤是显示一个表示动作的图标,可以通过设置UITableViewCell的 accessoryType来显示,默认是UITableViewCellAccessoryNone(不显⽰示辅助指⽰示视图), 其他值如下:

UITableViewCellAccessoryDisclosureIndicator

UITableViewCellAccessoryDetailDisclosureButton

UITableViewCellAccessoryCheckmark

还可以通过cell的accessoryView属性来自定义辅助指示视图(⽐如往右边放一个开关)

二、问题

cell的工作:在程序执行的时候,能看到多少条,它就创建多少条数据,如果视图滚动那么再创建新显示的内容。(系统自动调用)。即当一个cell出现在视野范围内的时候,就会调用创建一个cell。这样的逻辑看上去没有什么问题,但是真的没有任何问题吗?

当创建调用的时候,我们使用nslog打印消息,并打印创建的cell的地址。我们发现如果数据量非常大,用户在短时间内来回滚动的话,那么会创建大量的cell,一直开辟空间,且如果是往回滚,通过打印地址,我们会发现它并没有重用之前已经创建的cell,而是重新创建,开辟新的存储空间。

那有没有什么好的解决办法呢?

三、cell的重用原理

(1) iOS设备的内存有限,如果用UITableView显示成千上万条数据,就需要成千上万 个UITableViewCell对象的话,那将会耗尽iOS设备的内存。要解决该问题,需要重用UITableViewCell对象

(2)重⽤原理:当滚动列表时,部分UITableViewCell会移出窗口,UITableView会将窗口外的UITableViewCell放入一个对象池中,等待重用。当UITableView要求dataSource返回 UITableViewCell时,dataSource会先查看这个对象池,如果池中有未使用的UITableViewCell,dataSource则会用新的数据来配置这个UITableViewCell,然后返回给 UITableView,重新显示到窗口中,从而避免创建新对象 。这样可以让创建的cell的数量维持在很低的水平,如果一个窗口中只能显示5个cell,那么cell重用之后,只需要创建6个cell就够了。

(3)注意点:还有⼀个非常重要的问题:有时候需要自定义UITableViewCell(用⼀个子类继 承UITableViewCell),而且每⼀行⽤的不一定是同一种UITableViewCell,所以一 个UITableView可能拥有不同类型的UITableViewCell,对象池中也会有很多不同类型的 UITableViewCell,那么UITableView在重⽤用UITableViewCell时可能会得到错误类型的 UITableViewCell

解决⽅方案:UITableViewCell有个NSString *reuseIdentifier属性,可以在初始化UITableViewCell的时候传入一个特定的字符串标识来设置reuseIdentifier(一般用UITableViewCell的类名)。当UITableView要求dataSource返回UITableViewCell时,先 通过一个字符串标识到对象池中查找对应类型的UITableViewCell对象,如果有,就重用,如果没有,就传入这个字符串标识来初始化⼀一个UITableViewCell对象。

图片示例:

说明:一个窗口放得下(可视)三个cell,整个程序只需要创建4个该类型的cell即可。

四、cell的优化代码

代码示例:

1 #import "NJViewController.h"

2 #import "NJHero.h"

3

4 // #define ID @"ABC"

5

6 @interface NJViewController ()UITableViewDataSource, UITableViewDelegate

7 /**

8 * 保存所有的英雄数据

9 */

10 @property (nonatomic, strong) NSArray *heros;

11 @property (weak, nonatomic) IBOutlet UITableView *tableView;

12

13 @end

14

15 @implementation NJViewController

16

17 #pragma mark - 懒加载

18 - (NSArray *)heros

19 {

20 if (_heros == nil) {

21 // 1.获得全路径

22 NSString *fullPath = [[NSBundle mainBundle] pathForResource:@"heros" ofType:@"plist"];

23 // 2.更具全路径加载数据

24 NSArray *dictArray = [NSArray arrayWithContentsOfFile:fullPath];

25 // 3.字典转模型

26 NSMutableArray *models = [NSMutableArray arrayWithCapacity:dictArray.count];

27 for (NSDictionary *dict in dictArray) {

28 NJHero *hero = [NJHero heroWithDict:dict];

29 [models addObject:hero];

30 }

31 // 4.赋值数据

32 _heros = [models copy];

33 }

34 // 4.返回数据

35 return _heros;

36 }

37

38 - (void)viewDidLoad

39 {

40 [super viewDidLoad];

41 // 设置Cell的高度

42 // 当每一行的cell高度一致的时候使用属性设置cell的高度

43 self.tableView.rowHeight = 160;

44 }

45

46 #pragma mark - UITableViewDataSource

47 // 返回多少组

48 - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView

49 {

50 return 1;

51 }

52 // 返回每一组有多少行

53 - (NSInteger) tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section

54 {

55 return self.heros.count;

56 }

57 // 当一个cell出现视野范围内的时候就会调用

58 // 返回哪一组的哪一行显示什么内容

59 - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath

60 {

61 // 定义变量保存重用标记的值

62 static NSString *identifier = @"hero";

63

64 // 1.先去缓存池中查找是否有满足条件的Cell

65 UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:identifier];

66 // 2.如果缓存池中没有符合条件的cell,就自己创建一个Cell

67 if (cell == nil) {

68 // 3.创建Cell, 并且设置一个唯一的标记

69 cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:identifier];

70 NSLog(@"创建一个新的Cell");

71 }

72 // 4.给cell设置数据

73 NJHero *hero = self.heros[indexPath.row];

74 cell.textLabel.text = hero.name;

75 cell.detailTextLabel.text = hero.intro;

76 cell.imageView.image = [UIImage imageNamed:hero.icon];

77

78 // NSLog(@"%@ - %d - %p", hero.name, indexPath.row, cell);

79

80 // 3.返回cell

81 return cell;

82 }

83

84 #pragma mark - 控制状态栏是否显示

85 /**

86 * 返回YES代表隐藏状态栏, NO相反

87 */

88 - (BOOL)prefersStatusBarHidden

89 {

90 return YES;

91 }

92 @end

iOS的UI开发中Button的基本编写方法解析

一、简单说明

一般情况下,点击某个控件后,会做出相应反应的都是按钮

按钮的功能比较多,既能显示文字,又能显示图片,还能随时调整内部图片和文字的位置

二、按钮的三种状态

normal(普通状态)

默认情况(Default)

对应的枚举常量:UIControlStateNormal

highlighted(高亮状态)

按钮被按下去的时候(手指还未松开)

对应的枚举常量:UIControlStateHighlighted

disabled(失效状态,不可用状态)

如果enabled属性为NO,就是处于disable状态,代表按钮不可以被点击

对应的枚举常量:UIControlStateDisabled

三、注意点

(1)从Xcode5开始,图片资源都放到Images.xcassets中进行管理,可以使用拖拽的方式添加项目中用到的图片到Images.xcassets中

(2)若干多个控件共用一段代码,通常使用tag。

四、代码示例

(1)

复制代码 代码如下:

#import "LFViewController.h"

@interface LFViewController ()

@property (weak, nonatomic) IBOutlet UIButton *headImageView;

@end

@implementation LFViewController

// 在OC中,绝大多数的控件的监听方法的第一个参数就是控件本身

//- (IBAction)left:(UIButton *)button {

//

// NSLog(@"----");

//}

- (IBAction)move

{

// 通过frame修改head的位置

// 在OC中,不允许直接修改“对象”的“结构体属性”的“成员”

// 允许修改“对象”的'“结构体属性”

// 1. 取出结构体属性

CGRect rect = self.headImageView.frame;

// 2. 修改结构体成员

rect.origin.y -= 20;

// 3. 设置对象的结构体属性

self.headImageView.frame = rect;

}

(2)

复制代码 代码如下:

#import "LFViewController.h"

使用git

1. 创建项目时,勾选git

2. 开发告一段落后,选择"Source Control""Commit",并编写注释

// 枚举类型实质上就是一个整数,作用就是用来替代魔法数字

// 枚举类型中,指定了第一个整数之后,后面的数字会递增

typedef enum

kMovingDirTop = 10,

kMovingDirBottom,

kMovingDirLeft,

kMovingDirRight,

} kMovingDir;

#define kMovingDelta 50

@interface LFViewController ()

@property (weak, nonatomic) IBOutlet UIButton *headImageView;

@end

@implementation LFViewController

- (IBAction)move:(UIButton *)button

// CGRect rect = self.headImageView.frame;

CGPoint p = self.headImageView.center;

// magic number魔法数字,其他程序员看到代码的时候,不知道是什么意思

switch (button.tag) {

case kMovingDirTop:

p.y -= kMovingDelta;

break;

case kMovingDirBottom:

p.y += kMovingDelta;

break;

case kMovingDirLeft:

p.x -= kMovingDelta;

break;

case kMovingDirRight:

p.x += kMovingDelta;

break;

[UIView beginAnimations:nil context:nil];

[UIView setAnimationDuration:1.0];

self.headImageView.center = p;

[UIView commitAnimations];

- (IBAction)zoom:(UIButton *)button

CGRect rect = self.headImageView.bounds;

// 在C语言中,关于bool的判断:非零即真

if (button.tag) {

rect.size.width += 50;

rect.size.height += 50;

rect.size.width -= 50;

rect.size.height -= 50;

// 首尾动画

// beginAnimations表示此后的代码要“参与到”动画中

[UIView beginAnimations:nil context:nil];

[UIView setAnimationDuration:2.0];

self.headImageView.bounds = rect;

// self.headImageView.alpha = 0;

// commitAnimations,将beginAnimation之后的所有动画提交并生成动画

[UIView commitAnimations];

@end

五、补充笔记

1. IBAction的参数

- (IBAction)left:(UIButton *)button

(1) 在OC中,绝大多数的控件监听方法的第一个参数就是控件本身

(2) 默认连线时的参数类型是id

(3) 如果要在监听方法中,方便控件的使用,可以在连线时或者连线后,修改监听方法的参数类型

2. 修改对象的结构体成员

在OC中,不允许直接修改“对象”的“结构体属性”的“成员”,但是允许修改“对象”的“结构体属性”

修改结构体属性的成员方法如下:

(1)使用临时变量记录对象的结构体属性

(2) 修改临时变量的属性

(3)将临时变量重新设置给对象的结构体属性

3. 在程序开发中需要避免出现魔法数字(Magic Number)

使用枚举类型,可以避免在程序中出现魔法数字

(1)枚举类型实质上就是一个整数,其作用就是用来替代魔法数字

(2)枚举类型中,指定了第一个整数之后,后面的数字会递增

4. frame bounds center

1 frame可以修改对象的位置和尺寸

2 bounds可以修改对象的尺寸

3 center可以修改对象的位置

5. 首尾式动画

复制代码 代码如下:

// beginAnimations表示此后的代码要“参与到”动画中

[UIView beginAnimations:nil context:nil];

// setAnimationDuration用来指定动画持续时间

[UIView setAnimationDuration:2.0];

self.headImageView.bounds = rect;

......

// commitAnimations,将beginAnimation之后的所有动画提交并生成动画

[UIView commitAnimations];

下面来罗列一下UIButton的基本属性罗列

第一、UIButton的定义

复制代码 代码如下:

UIButton *button=[[UIButton buttonWithType:(UIButtonType);

能够定义的button类型有以下6种,

复制代码 代码如下:

typedef enum {

UIButtonTypeCustom = 0, 自定义风格

UIButtonTypeRoundedRect, 圆角矩形

UIButtonTypeDetailDisclosure, 蓝色小箭头按钮,主要做详细说明用

UIButtonTypeInfoLight, 亮色感叹号

UIButtonTypeInfoDark, 暗色感叹号

UIButtonTypeContactAdd, 十字加号按钮

}UIButtonType;

第二、设置frame

复制代码 代码如下:

button1.frame = CGRectMake(20, 20, 280, 40);

[button setFrame:CGRectMake(20,20,50,50)];

第三、button背景色

复制代码 代码如下:

button1.backgroundColor = [UIColor clearColor];

[button setBackgroundColor:[UIColor blueColor]];

第四、state状态

forState: 这个参数的作用是定义按钮的文字或图片在何种状态下才会显现

复制代码 代码如下:

enum {

UIControlStateNormal = 0, 常规状态显现

UIControlStateHighlighted = 1 0, 高亮状态显现

UIControlStateDisabled = 1 1, 禁用的状态才会显现

UIControlStateSelected = 1 2, 选中状态

UIControlStateApplication = 0x00FF0000, 当应用程序标志时

UIControlStateReserved = 0xFF000000 为内部框架预留,可以不管他

@property(nonatomic,getter=isEnabled)BOOL enabled; // default is YES. if NO, ignores touch events and subclasses may draw differently

@property(nonatomic,getter=isSelected)BOOL selected; // default is NO may be used by some subclasses or by application

@property(nonatomic,getter=isHighlighted)BOOL highlighted;

第五 、设置button填充图片和背景图片

复制代码 代码如下:

[buttonsetImage:[UIImageimageNamed:@"checkmarkControllerIcon"]forState:UIControlStateNormal];

[buttonsetBackgroundImage:[UIImageimageNamed:@"checkmarkControllerIcon"]forState:UIControlStateNormal];

第六、设置button标题和标题颜色

复制代码 代码如下:

[button1 setTitle:@"点击" forState:UIControlStateNormal];

[buttonsetTitleColor:[UIColorredColor]forState:UIControlStateNormal];

第七、设置按钮按下会发光

复制代码 代码如下:

button.showsTouchWhenHighlighted=NO;

第八、添加或删除事件处理

复制代码 代码如下:

[button1 addTarget:self action:@selector(butClick:) forControlEvents:UIControlEventTouchUpInside];

[btn removeTarget:nil action:nil forControlEvents:UIControlEventTouchUpInside];

第九、 设置按钮内部图片间距和标题间距

复制代码 代码如下:

UIEdgeInsets insets; // 设置按钮内部图片间距

insets.top = insets.bottom = insets.right = insets.left = 10;

bt.contentEdgeInsets = insets;

bt.titleEdgeInsets = insets; // 标题间距

ios开发uicollectionview怎么给布局类转进值

UICollectionView 和 UICollectionViewController 类是iOS6 新引进的API,用于展示集合视图,布局更加灵活,可实现多列布局,用法类似于UITableView 和 UITableViewController 类。 使用UICollectionView 必须实现UICollectionViewDataSource,


网页名称:ios开发ui工厂类,ios的ui设计
本文来源:http://cqcxhl.com/article/dsseecd.html

其他资讯

在线咨询
服务热线
服务热线:028-86922220
TOP