自定义UIButton的时候遇到的小问题
出现问题的代码如下:
1 | //选择按钮 |
结果是看不到你添加的标题。
问题的关键是如何解决的,呵呵,蠢死我了,其实就是自己设计的button的宽度太小了,没有将字体显示出来.
结果的代码如下修改就好:
1 | //选择按钮 |
出现问题的代码如下:
1 | //选择按钮 |
结果是看不到你添加的标题。
问题的关键是如何解决的,呵呵,蠢死我了,其实就是自己设计的button的宽度太小了,没有将字体显示出来.
结果的代码如下修改就好:
1 | //选择按钮 |
由于自己也在学习ios开发,也经常的会关注developer.app.com,因此今天有幸看到这篇文章,自己英语也不是很好,综合google和海词,大概了解了一下标题的意思,(https://developer.apple.com/library/ios/#qa/qa1763/_index.html#//apple_ref/doc/uid/DTS40012165
)这个是文章的地址,这里算是做个笔记,方便自己下次看看。这篇文章整体就是说代表一个团队分发一个app,应该是用于这个团队的测试使用吧。(也许有错,还希望大牛看到后 指点一下)。
那么接下来的结局方案就是如下了:
Add the build engineer to the development team with the role of Admin through the Member Center. For more information on defining team roles, see Managing Your Team. The Admin role is required to manage the team distribution certificate.
If the distribution build will be submitted to the App Store, add the build engineer to the team users on iTunes Connect with the role of Technical User. This allows the build engineer to log into iTunes Connect with their own credentials while submitting the app. Skip this step if the build is being used for Ad Hoc beta testing. For more info about the Technical User role in iTunes Connect, see Managing Users in the iTunes Connect Developer Guide.
The build engineer should then…
我就直接复制了一下,其实步骤很简单的,基本上能够看的明白。
只不过这里提到了几点Importment:
This Q&A is exclusively for iOS App Store apps. The process within this document should not be followed for the Enterprise Developer Program. Please consult Apple DTS with any questions before leveraging this document, or if you are unsure of your developer program type.
这条就是说这个需求不适合企业开发者项目,显然不是企业开发者,就是个人的喽,呵呵。
另外一点就是
A single email address has access to only one iTunes Connect account, unlike the Member Center, which supports multiple teams per Apple ID. Therefore the build engineer must supply a new unique email address that is not already associated to another iTunes Connect account.
一个email地址只允许链接一个iTunes账户,作为一个bulid enginner 必须有一个email,这个email没有链接多个iTunes账户。好了就这么多了。有不懂的大家一起探讨
NSDateFormatter自定义日期/时间格式 ,简单的举一个例子,看下面的代码就可以了
1 | NSDate *dateValue = [NSDate date]; |
下面附上几个格式:
1 | yyyy:MM:dd G 'at' HH:mm:ss zzz 1996.07.10 AD at 15:08:56 PDT |
下面是得到当前的年,月,日,时,分,秒。
1 | NSCalendar *cal = [NSCalendar currentCalendar]; |
当然不止这些的,有兴趣的可以去参考一下:http://unicode.org/reports/tr35/tr35-6.html#Date\_Format\_Patterns
自定义的UIActionSheet ,网上找了好久,都没有完整的解决办法,于是自己 经过查找资料,然后根据自己的项目需要做了一些改动,得到了一个完整版的,自定义的UIActionSheet,代码如下:
1 | -(void) setUpDatePicker |
这里简单的解释一下:
-(void) setUpDatePicker方法用于调用UIDatePicker
-(void) DatePickerDoneClick:(id) sender方法用于实现隐藏UIdatePicker
-(void) dateChanged:(id)sender方法实现获取日期结果值的方法。
如果没有实现效果,别忘记加上协议,这个是比较容易忘记的
IOS关于NSString追加字符串的问题,网上也有不少的做法,比较多的做法是:
1 | NSMutableString *str=[[NSMutableStringalloc] initWithString:@"dd"]; |
但是使用上面的方法,我不知道你们有没有遇到有类型不对的提示,总之我这里是有的,于是我将上面这样改了一下:
1 | NSString *str=[[NSMutableStringalloc] initWithString:@"dd"]; |
一开始的时候怎样修改都追加不上,类型也换了
应该是:把追加后的值回传给要追加的原对象
1 | str=[str stringByAppendingString:@"eee" ]; //正确 |
警告消失了。
点击屏幕任意空白处,键盘消失的方法:
在这个方法里面实现就好了:
1 | -(void) touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event |
在viewdidload的时候,把每个TextField设好tag。之后就可以根据最下面的UITextField的内容来判断键盘的弹出和关闭了
实例代码:
1 | - (void)textFieldDidBeginEditing:(UITextField *)textField |
初始化textfield并设置位置及大小UITextField *text = [[UITextField alloc]initWithFrame:CGRectMake(20, 20, 130, 30)];
设置边框样式,只有设置了才会显示边框样式
1 | text.borderStyle = UITextBorderStyleRoundedRect; |
设置输入框的背景颜色,此时设置为白色 如果使用了自定义的背景图片边框会被忽略掉text.backgroundColor = [UIColor whiteColor];
设置背景text.background = [UIImage imageNamed:@"dd.png"];
设置背景text.disabledBackground = [UIImage imageNamed:@"cc.png"];
当输入框没有内容时,水印提示 提示内容为passwordtext.placeholder = @"password";
设置输入框内容的字体样式和大小text.font = [UIFont fontWithName:@"Arial" size:20.0f];
设置字体颜色text.textColor = [UIColor redColor];
输入框中是否有个叉号,在什么时候显示,用于一次性删除输入框中的内容
1 | text.clearButtonMode = UITextFieldViewModeAlways; |
输入框中一开始就有的文字text.text = @"一开始就在输入框的文字";
每输入一个字符就变成点 用语密码输入text.secureTextEntry = YES;
是否纠错
1 | text.autocorrectionType = UITextAutocorrectionTypeNo; |
再次编辑就清空text.clearsOnBeginEditing = YES;
内容对齐方式text.textAlignment = UITextAlignmentLeft;
内容的垂直对齐方式 UITextField继承自UIControl, 此类中有一个属性contentVerticalAlignmenttext.contentVerticalAlignment = UIControlContentVerticalAlignmentCenter;
设置为YES时文本会自动缩小以适应文本窗口大小.默认是保持原来大小,而让长文本滚动textFied.adjustsFontSizeToFitWidth = YES;
设置自动缩小显示的最小字体大小text.minimumFontSize = 20;
设置键盘的样式
1 | text.keyboardType = UIKeyboardTypeNumberPad; |
1 | text.autocapitalizationType = UITextAutocapitalizationTypeNone; |
1 | text.returnKeyType =UIReturnKeyDone; |
1 | textView.keyboardAppearance=UIKeyboardAppearanceDefault; |
设置代理 用于实现协议text.delegate = self;
把textfield加到视图中[self.window addSubview:text];
最右侧加图片是以下代码 左侧类似
1 | UIImageView *image=[[UIImageView alloc] initWithImage:[UIImage imageNamed:@"right.png"]]; |
text.delegate = self;
声明text的代理是我,我会去实现把键盘往下收的方法 这个方法在UITextFieldDelegate里所以我们要采用UITextFieldDelegate这个协议1 | - (BOOL)textFieldShouldReturn:(UITextField *)textField { |
除了UITextField对象的风格选项,你还可以定制化UITextField对象,为他添加许多不同的重写方法,来改变文本字段的显示行为。这些方法都会返回一个CGRect结构,制定了文本字段每个部件的边界范围。以下方法都可以重写。
textRectForBounds: // 重写来重置文字区域
drawTextInRect: // 改变绘文字属性.重写时调用super可以按默认图形属性绘制,若自己完全重写绘制函数,就不用调用super了.
placeholderRectForBounds: // 重写来重置占位符区域
drawPlaceholderInRect: // 重写改变绘制占位符属性.重写时调用super可以按默认图形属性绘制,若自己完全重写绘制函数,就不用调用super了.
borderRectForBounds: // 重写来重置边缘区域
editingRectForBounds: // 重写来重置编辑区域
clearButtonRectForBounds: // 重写来重置clearButton位置,改变size可能导致button的图片失真
leftViewRectForBounds:
rightViewRectForBounds:
1 | - (BOOL)textFieldShouldBeginEditing:(UITextField *)textField{ |
UITextField派生自UIControl,所以UIControl类中的通知系统在文本字段中也可以使用。除了UIControl类的标准事件,你还可以使用下列UITextField类特有的事件
当文本字段退出编辑模式时触发。通知的object属性存储了最终文本。
因为文本字段要使用键盘输入文字,所以下面这些事件发生时,也会发送动作通知
限制只能输入特定的字符
1 | (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string |
上面那个NUMBERS是一个宏,可以在文件顶部定义:#define NUMBERS @”0123456789\n”
(这个代表可以输入数字和换行,请注意这个\n,如果不写这个,Done按键将不会触发,如果用在SearchBar中,将会不触发Search事件,因为你自己限制不让输入\n,好惨,我在项目中才发现的。)
所以,如果你要限制输入英文和数字的话,就可以把这个定义为:#define kAlphaNum @”ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789″
。
当然,你还可以在以上方法return之前,做一提示的,比如提示用户只能输入数字之类的。如果你觉得有需要的话。
限制只能输入一定长度的字符
1 | - (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string |
我在用UITextView的时候,默认是不能设置placeholder的,于是网上找了一些资料,最后找到了一个别人写的自定义类,拿来用用,顺便分享一下。
1 | // |
1 | // |
先在github上创建并写好相关名字,描述。(github的创建,可以参考这里https://help.github.com/articles/create-a-repo)
如果我们创建了hello-world,那么下面的操作如下:
1 | $cd ~/hello-world //到hello-world目录 |
1 | $cd ~/hello-world |
1 | $cd ~/hello-world |
1 | $cd ~/hello-world |
然后就可以git add . 能自动过滤这种文件
1 | $git clone xx@xx:zhangda89/hello-world.git //假如本地已经存在了代码,而仓库里有更新,把更改的合并到本地的项目: |
1 | $git reset |
1 | $git rm * // 不是用rm |
git remote add origin [email protected]:zhangda89/hello-world.git
错误提示:fatal: remote origin already exists.
解决办法: $git remote rm origin
然后在执行:$git remote add origin [email protected]:zhangda89/hello-world.git
就不会报错误了
git push origin master
错误提示:error:failed to push som refs to
解决办法: $git pull origin master
//先把远程服务器github上面的文件拉先来,再push 上去。