实际应用中经常用的代码片段,但是没有必要记住的
来源:互联网 发布:sql 附加数据库 编辑:程序博客网 时间:2024/06/05 05:42
目录
1、获取键盘的高度
2、创建键盘上的完成按钮
3、设置button按钮中的文字居中方式
4、自己绘制一张背景图
1、获取键盘的高度
NSDictionary *userInfo = [aNotificationuserInfo];
NSValue *aValue = [userInfoobjectForKey:UIKeyboardFrameEndUserInfoKey];
CGRect keyboardRect = [aValueCGRectValue];
self.keyboardEndHeight = keyboardRect.size.height;
self.keyboardEndHeight 自定义的2、创建键盘上的完成按钮
- (UIToolbar *)createToolbar
{
UIToolbar *toolBar = [[UIToolbaralloc] initWithFrame:CGRectMake(0,0, KSCREENSIZE.width,44)];
UIBarButtonItem *space = [[UIBarButtonItemalloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpacetarget:nilaction:nil];
UIBarButtonItem *done = [[UIBarButtonItemalloc] initWithTitle:@"完成"style:UIBarButtonSystemItemDonetarget:selfaction:@selector(textFieldDone)];
toolBar.items =@[space, done];
return toolBar;
}
- (void)textFieldDone
{
[[selffindFirstResponder] resignFirstResponder];
}
3、设置button按钮中的文字居中方式
UIToolbar *toolBar = [selfcreateToolbar];
textField.inputAccessoryView = toolBar;
4、自己绘制一张背景图
// 不同情况的背景图 可以设置高亮状态下的颜色
+ (UIImage *)backgroundImageForButtonWithBounds:(CGRect)bounds normalColor:(UIColor*)normalColor hightedColor:(UIColor*)hightedColor isShenqing:(BOOL)shenqing
{//自绘了一张背景图
CGRect canvasRect = bounds;
CGRect paintingRect =CGRectMake(0,0, canvasRect.size.width, canvasRect.size.height);;
UIGraphicsBeginImageContext(canvasRect.size);
CGContextRef context =UIGraphicsGetCurrentContext();
if (shenqing) {
CGContextSetFillColorWithColor(context, [normalColorCGColor]);
} else {
CGContextSetFillColorWithColor(context, [hightedColorCGColor]);
}
CGContextFillRect(context, paintingRect);
UIImage *image =UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return image;
}
- 实际应用中经常用的代码片段,但是没有必要记住的
- Java实际应用中经常遇到的"装饰模式"总结
- 一些在android开发中经常用的的代码片段
- 一些在android开发中经常用的的代码片段
- 10个经常用的php片段
- 开发者经常使用的15个jQuery代码片段
- C#程序员经常用到的10个实用代码片段
- C#程序员经常用到的10个实用代码片段
- C#程序员经常用到的10个实用代码片段
- C#程序员经常用到的10个实用代码片段
- C#程序员经常用到的10个实用代码片段
- C#程序员经常用到的10个实用代码片段
- JQ实际项目中经常用到的知识点--总结
- android 调用应用的代码片段
- 一些经常使用的技术【需要记住】
- Android开发中一些直接拿来用的代码片段
- Android开发中一些直接拿来用的代码片段
- VC中调用JavaScript的代码片段
- css背景样式
- python-opencv颜色提取分割
- 单片机的时钟分频
- 特征降维
- C++第一次上机实验报告—01
- 实际应用中经常用的代码片段,但是没有必要记住的
- 【leetcode】Array——Maximal Rectangle(85)
- tree
- AndroidStudio运行项目出现Failure [INSTALL_FAILED_DEXOPT]
- 用循环求
- 程序设计作业报告
- android日期选择器,从底部弹出的日期选择器,有点像IOS日期选择器
- BP算法的回归
- Android中实现推送方式的基础知识及相关解决方案