iOS开发UI篇xib的简单使用Word文件下载.docx

上传人:b****8 文档编号:22363074 上传时间:2023-02-03 格式:DOCX 页数:14 大小:988.66KB
下载 相关 举报
iOS开发UI篇xib的简单使用Word文件下载.docx_第1页
第1页 / 共14页
iOS开发UI篇xib的简单使用Word文件下载.docx_第2页
第2页 / 共14页
iOS开发UI篇xib的简单使用Word文件下载.docx_第3页
第3页 / 共14页
iOS开发UI篇xib的简单使用Word文件下载.docx_第4页
第4页 / 共14页
iOS开发UI篇xib的简单使用Word文件下载.docx_第5页
第5页 / 共14页
点击查看更多>>
下载资源
资源描述

iOS开发UI篇xib的简单使用Word文件下载.docx

《iOS开发UI篇xib的简单使用Word文件下载.docx》由会员分享,可在线阅读,更多相关《iOS开发UI篇xib的简单使用Word文件下载.docx(14页珍藏版)》请在冰豆网上搜索。

iOS开发UI篇xib的简单使用Word文件下载.docx

5//Createdbyappleon14-5-24.

6//Copyright(c)2014年itcase.Allrightsreserved.

7//

8

9#import"

YYViewController.h"

10#import"

YYapp.h"

11

12@interfaceYYViewController()

13@property(nonatomic,strong)NSArray*app;

14@end

15

16@implementationYYViewController

17

18//1.加载数据信息

19-(NSArray*)app

20{

21if(!

_app){

22NSString*path=[[NSBundlemainBundle]pathForResource:

@"

app.plist"

ofType:

nil];

23NSArray*temparray=[NSArrayarrayWithContentsOfFile:

path];

24

25//字典转模型

26NSMutableArray*arrayM=[NSMutableArrayarray];

27for(NSDictionary*dictintemparray){

28[arrayMaddObject:

[YYappappWithDict:

dict]];

29}

30_app=arrayM;

31}

32return_app;

33}

34

35//创建界面原型

36-(void)viewDidLoad

37{

38[superviewDidLoad];

39NSLog(@"

%d"

self.app.count);

40

41//九宫格布局

42inttotalloc=3;

43CGFloatappviewW=80;

44CGFloatappviewH=90;

45CGFloatmargin=(self.view.frame.size.width-totalloc*appviewW)/(totalloc+1);

46

47intcount=self.app.count;

48for(inti=0;

i<

count;

i++){

49

50introw=i/totalloc;

51intloc=i%totalloc;

52CGFloatappviewX=margin+(margin+appviewW)*loc;

53CGFloatappviewY=margin+(margin+appviewH)*row;

54YYapp*app=self.app[i];

55

56//拿出xib视图

57NSArray*apparray=[[NSBundlemainBundle]loadNibNamed:

appxib"

owner:

niloptions:

58UIView*appview=[apparrayfirstObject];

59//加载视图

60appview.frame=CGRectMake(appviewX,appviewY,appviewW,appviewH);

61

62UIImageView*appviewImg=(UIImageView*)[appviewviewWithTag:

1];

63appviewImg.image=app.image;

64

65UILabel*appviewlab=(UILabel*)[appviewviewWithTag:

2];

66appviewlab.text=app.name;

67

68UIButton*appviewbtn=(UIButton*)[appviewviewWithTag:

3];

69[appviewbtnaddTarget:

selfaction:

@selector(appviewbtnClick:

)forControlEvents:

UIControlEventTouchUpInside];

70appviewbtn.tag=i;

71

72[self.viewaddSubview:

appview];

73}

74}

75

76/**按钮的点击事件*/

77-(void)appviewbtnClick:

(UIButton*)btn

78{

79YYapp*apps=self.app[btn.tag];

80UILabel*showlab=[[UILabelalloc]initWithFrame:

CGRectMake(60,450,200,20)];

81[showlabsetText:

[NSStringstringWithFormat:

@"

%@下载成功"

apps.name]];

82[showlabsetBackgroundColor:

[UIColorlightGrayColor]];

83[self.viewaddSubview:

showlab];

84showlab.alpha=1.0;

85

86//简单的动画效果

87[UIViewanimateWithDuration:

2.0animations:

^{

88showlab.alpha=0;

89}completion:

^(BOOLfinished){

90[showlabremoveFromSuperview];

91}];

92}

93

94@end

运行效果:

三、对xib进行连线示例

1.连线示例

新建一个xib对应的视图类,继承自Uiview

在xib界面右上角与新建的视图类进行关联

把xib和视图类进行连线

注意:

在使用中把weak改成为强引用。

否则...

2.连线后的代码示例

11#import"

YYappview.h"

12

13@interfaceYYViewController()

14@property(nonatomic,strong)NSArray*app;

15@end

16

17@implementationYYViewController

18

19//1.加载数据信息

20-(NSArray*)app

21{

22if(!

23NSString*path=[[NSBundlemainBundle]pathForResource:

24NSArray*temparray=[NSArrayarrayWithContentsOfFile:

25

26//字典转模型

27NSMutableArray*arrayM=[NSMutableArrayarray];

28for(NSDictionary*dictintemparray){

29[arrayMaddObject:

30}

31_app=arrayM;

32}

33return_app;

34}

35

36//创建界面原型

37-(void)viewDidLoad

38{

39[superviewDidLoad];

40NSLog(@"

41

42//九宫格布局

43inttotalloc=3;

44CGFloatappviewW=80;

45CGFloatappviewH=90;

46CGFloatmargin=(self.view.frame.size.width-totalloc*appviewW)/(totalloc+1);

47

48intcount=self.app.count;

49for(inti=0;

50

51introw=i/totalloc;

52intloc=i%totalloc;

53CGFloatappviewX=margin+(margin+appviewW)*loc;

54CGFloatappviewY=margin+(margin+appviewH)*row;

55YYapp*app=self.app[i];

56

57//拿出xib视图

58NSArray*apparray=[[NSBundlemainBundle]loadNibNamed:

59

60//注意这里的类型名!

61//UIView*appview=[apparrayfirstObject];

62YYappview*appview=[apparrayfirstObject];

63

64//加载视图

65appview.frame=CGRectMake(appviewX,appviewY,appviewW,appviewH);

66[self.viewaddSubview:

68appview.appimg.image=app.image;

69appview.applab.text=app.name;

70appview.appbtn.tag=i;

72[appview.appbtnaddTarget:

73

75}

76

77/**按钮的点击事件*/

78-(void)appviewbtnClick:

79{

80YYapp*apps=self.app[btn.tag];

81UILabel*showlab=[[UILabelalloc]initWithFrame:

82[showlabsetText:

83[showlabsetBackgroundColor:

84[self.viewaddSubview:

85showlab.alpha=1.0;

86

87//简单的动画效果

88[UIViewanimateWithDuration:

89showlab.alpha=0;

90}completion:

91[showlabremoveFromSuperview];

92}];

93}

94

95@end

YYappview.h文件代码(已经连线)

#import<

UIKit/UIKit.h>

@interfaceYYappview:

UIView

@property(strong,nonatomic)IBOutletUIImageView*appimg;

@property(strong,nonatomic)IBOutletUILabel*applab;

@property(strong,nonatomic)IBOutletUIButton*appbtn;

@end

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > 解决方案 > 其它

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1