-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathiOS--UI.html
More file actions
243 lines (191 loc) · 8.52 KB
/
iOS--UI.html
File metadata and controls
243 lines (191 loc) · 8.52 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<title>iOS--UI</title>
<link rel="stylesheet" href="templates/SyntaxHighlighter.css"></link>
<link rel="stylesheet" href="templates/style.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js"></script>
<script language="javascript" src="templates/shCore.js"></script>
<script language="javascript" src="templates/shBrushCpp.js"></script>
<script language="javascript" src="templates/shBrushJScript.js"></script>
<script language="javascript" src="templates/shBrushPhp.js"></script>
<script language="javascript" src="templates/shBrushJava.js"></script>
<script language="javascript" src="templates/shBrushXml.js"></script>
<script language="javascript" src="templates/shBrushCss.js"></script>
<script language="javascript" src="templates/shBrushObjectiveC.js"></script>
<script language="javascript" src="templates/vimwiki.js"></script>
</head>
<body>
<div class="navbar">
<div class="navbar-container">
<a class="brand" href="index.html">NieNet</a>
<div class="nav-collapse">
<ul class="nav">
<li><a href="index.html">主页</a></li>
<li><a href="about.html">关于</a></li>
</ul>
</div><!--/.nav-collapse -->
</div>
</div>
<div class="container">
<div id="content">
<h2 id="toc_0.1">iOS--UI</h2>
<p>
Don't know if it helps your specific problem, however UITextAlignmentCenter does work if you use initWithStyle:UITableViewCellStyleDefault
</p>
<h2 id="toc_0.2">loadView</h2>
<p>
loadView仅仅应该在开发者希望自行通过编码而不是Interface Builder定制view的时候被实现,而且不应该在其中调用[super loadView],你的loadView中应该有self.view = xxx这样的行为。
</p>
<p>
如果仅仅是想要在当前view上增加一些UIButton或是UILabel,应该在viewDidLoad里使用[self.view addSubView:xxx]去做,此时不要实现自己的loadView。下面是重写loadView的一个案例。
</p>
<pre name="code" class="c">
- ( void ) loadView {
UIView *view = [ [ UIView alloc] initWithFrame:[ UIScreen
mainScreen] .applicationFrame] ;
[ view setBackgroundColor:_color] ;
self.view = view;
[ view release] ;
}
</pre>
<p>
你在控制器中实现了loadView方法,那么你可能会在应用运行的某个时候被内存管理控制调用。 如果设备内存不足的时候, view 控制器会收到didReceiveMemoryWarning的消息。 默认的实现是检查当前控制器的view是否在使用。 如果它的view不在当前正在使用的view hierarchy里面,且你的控制器实现了loadView方法,那么这个view将被release, loadView方法将被再次调用来创建一个新的view。
</p>
<h2 id="toc_0.3">如何修改默认返回按钮的title</h2>
<p>
A视图-->B视图
</p>
<p>
现在想改变B视图返回A视图的返回按钮的title,只需在A视图中加上如下代码:
</p>
<pre name="code" class="c">
self.navigationItem.backBarButtonItem = [[UIBarButtonItem alloc]
initWithTitle:@"返回"
style:UIBarButtonItemStylePlain
target:self
action:nil];
</pre>
<p>
B视图不用做任何操作。
</p>
<p>
The backBarButtonItem exists specifically to change the appearance of the back button. If you need a custom action, you should consider using leftBarButtonItem instead.
</p>
<p>
下面就是使用leftBarButtonItem代替backBarButtonTtem的代码段,在B视图中viewDidLoad函数中实现。
</p>
<p>
在使用中发现,这样的实现其实是有问题的。返回按键只在B页面完全加载之后才出现,也就没有了从右向左滑入的效果。
</p>
<pre name="code" class="c">
//返回按键
UIBarButtonItem *backBarBtn = [[UIBarButtonItem alloc] initWithTitle:@"Back" style:UIBarButtonItemStylePlain target:self action:@selector(backItemAction:)];
UIImage *originalImage_normal = [UIImage imageNamed:@"nav_bar_back_button_normal.png"];
UIImage *originalImage_selected = [UIImage imageNamed:@"nav_bar_back_button_selected.png"];
UIImage *image_normal;
UIImage *image_selected;
// 拉伸图片
if ([[UIImage class] respondsToSelector:@selector(resizableImageWithCapInsets:)]) {
image_normal = [originalImage_normal resizableImageWithCapInsets:UIEdgeInsetsMake(0, 12.5, 0, 7.5)];
image_selected = [originalImage_selected resizableImageWithCapInsets:UIEdgeInsetsMake(0, 12.5, 0, 7.5)];
}
else {
image_normal = [originalImage_normal stretchableImageWithLeftCapWidth:12.5 topCapHeight:0];
image_selected = [originalImage_selected stretchableImageWithLeftCapWidth:12.5 topCapHeight:0];
}
[backBarBtn setBackgroundImage:image_normal forState:UIControlStateNormal barMetrics:UIBarMetricsDefault];
[backBarBtn setBackgroundImage:image_selected forState:UIControlStateHighlighted barMetrics:UIBarMetricsDefault];
self.navigationItem.leftBarButtonItem = backBarBtn;
self.navigationItem.leftBarButtonItem.target = self;
[backBarBtn release];
</pre>
<h2 id="toc_0.4">获取iphone屏幕的宽度</h2>
<pre name="code" class="c">
CGRect r = [ UIScreen mainScreen ].applicationFrame;
r=0,20,320,460
CGRect rx = [ UIScreen mainScreen ].bounds;
r=0,0,320,480
</pre>
<h2 id="toc_0.5">在cell中添加subview图片</h2>
<pre name="code" class="c">
cell.inputView 或者 cell.contentView
// Configure the cell...
for (UIImageView *item in [cell.contentView subviews]) {
if ([item isKindOfClass:[UIImageView class]]) {
[item removeFromSuperview];
}
}
</pre>
<h2 id="toc_0.6">模态视图 presentModalViewController</h2>
<pre name="code" class="c">
-(void)firstpressed
{
//[[(ASSAppDelegate*)[UIApplication sharedApplication].delegate topStatusBar] setHidden:NO];
[self.navigationController presentModalViewController:[[ASSRootViewController alloc] init] animated:YES];
}
</pre>
<h2 id="toc_0.7">关于覆盖层</h2>
<p>
下面是一段覆盖层的代码,特点是使用了keyWindow。
</p>
<pre name="code" class="c">
- (id)init
{
CGRect frame = CGRectMake(0, 0, 320.0f, 400.0f);
if((self = [super initWithFrame:frame]))
{
[super setBackgroundColor:[UIColor clearColor]];
UIWindow *keyWindow = [[UIApplication sharedApplication] keyWindow];
UIImageView *dimView = [[UIImageView alloc] initWithFrame:keyWindow.bounds];
dimView.image = [self backgroundGradientImageWithSize:keyWindow.bounds.size];
dimView.userInteractionEnabled = YES;
[keyWindow addSubview:dimView];
[self setCenter:CGPointMake(dimView.frame.size.width/2, dimView.frame.size.height/2)];
[dimView addSubview:self];
//...
}
}
</pre>
<h2 id="toc_0.8">removeFromSuperview</h2>
<pre name="code" class="c">
[_overlay removeFromSuperview];
[_transition removeFromSuperview];
</pre>
<p>
_overlay等在removeFromSupperview之后就会被释放掉(release)。
</p>
<blockquote>
If the receiver’s superview is not nil, the superview releases the receiver. If you plan to reuse a view, be sure to retain it before calling this method and release it again later as appropriate.
</blockquote>
<h2 id="toc_0.9">IOS中view页面的堆栈操作</h2>
<pre name="code" class="c">
[self.navigationController popViewControllerAnimated:YES];
</pre>
<h2 id="toc_0.10">headView使用addSubview之后,不能够delease</h2>
<pre name="code" class="c">
UIView* headView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 300, 30)];
headView.backgroundColor = [UIColor redColor];
UILabel* headLabel = [[UILabel alloc] initWithFrame:CGRectMake(20,10, 200, 21)];
headLabel.backgroundColor = [UIColor greenColor];
headLabel.text = @"Available control system";
headLabel.textColor = [[UIColor alloc] initWithRed:128.0/255.0 green:133.0/255.0 blue:141.0/255.0 alpha:1.0];
//headLabel.center = CGPointMake(headLabel.frame.size.width/2+18, headView.frame.size.height-headLabel.frame.size.height/2);
headLabel.shadowColor = [UIColor whiteColor];
headLabel.shadowOffset = CGSizeMake(0.0f, 0.5f);
[headView addSubview:headLabel];
[headView addSubview:self.scaningIndicatorView];
//[headView release];
</pre>
</div>
</div>
<footer>
<p id="legal">Copyright © 2012 NIE-YONG. All Rights Reserved.</p>
</footer>
<a class="go2top" style="display: none;"><span></span></a>
</body>
<script language="javascript">
dp.SyntaxHighlighter.HighlightAll('code');
</script>
</html>