1、IOS7中使用ScrollView的时候需要对一个属性做操作,不然是没有办法正常使用的,即使你定义或者设置的属性和内容正确,也不会正常的
if ([self respondsToSelector:@selector(automaticallyAdjustsScrollViewInsets)]) {
self.automaticallyAdjustsScrollViewInsets=NO;}
2、IOS中系统方法之字母排序
NSArray *keys=[NSArray arrayWithArray:self.setions];
self.setions = [[NSMutableArray alloc]initWithArray:[keys sortedArrayUsingSelector:@selector(compare:)]];
3、由于首级视图标题太长了,然后我就想在第一级界面引用第二级界面的时候
然后就使用了
ViewController *vc=[ViewController alloc]init];
vc.navigationController.navigationController.navigationItem.backBarButtonItem.title=@"返回";
发现根本就不管用,后来查阅资料就解决了:
4、怎么代码实现修改searchbar中CancelButton的title
因为Cancle按钮要在[controller.searchBarsetShowsCancelButton:YES];后才会在子视图中有,所以不能在searchDisplayControllerWillBeginSearch方法中改变Cancle按钮,只能在
searchDisplayControllerDidBeginSearch方法中加入UIButton *cancelButton;
UIView *topView = controller.searchBar.subviews[0];
for (UIView *subViewin topView.subviews) {
if ([subViewisKindOfClass:NSClassFromString(@"UINavigationButton")]) {
cancelButton = (UIButton*)subView;
[cancelButtonsetTitle:@"取消"forState:UIControlStateNormal];
[cancelButtonaddTarget:selfaction:@selector(cancelBtn)forControlEvents:UIControlEventTouchUpInside];
}
}
4、无障碍的push视图
+(void)appPushVC:(UIViewController *)viewcontroller{
AppDelegate *app=(AppDelegate *) [[UIApplication sharedApplication] delegate];
UINavigationController *nav=(UINavigationController *)app.window.rootViewController;
[nav pushViewController:viewcontroller animated:YES];
}
5、想要给TextField添加Clear按钮,对于新版的iOS来说,直接在MainStoryboard.storyboard中设置TextField的属性Clear Button为Is always visible/Appears while editing/Appears unless editing即可。
1
|
myUITextField.clearButtonMode = UITextFieldViewModeWhileEditing;
|
The text string displayed in the “return” key of a keyboard.
typedef enum {
UIReturnKeyDefault,
UIReturnKeyGo,
UIReturnKeyGoogle,
UIReturnKeyJoin,
UIReturnKeyNext,
UIReturnKeyRoute,
UIReturnKeySearch,
UIReturnKeySend,
UIReturnKeyYahoo,
UIReturnKeyDone,
UIReturnKeyEmergencyCall,
} UIReturnKeyType;
Constants
UIReturnKeyDefault
Set the text of the return key to “return”.
Available in iPhone OS 2.0 and later.
Declared in UITextInputTraits.h.
UIReturnKeyGo
Set the text of the return key to “Go”.
Available in iPhone OS 2.0 and later.
Declared in UITextInputTraits.h.
UIReturnKeyGoogle
Set the text of the return key to “Google”.
Available in iPhone OS 2.0 and later.
Declared in UITextInputTraits.h.
UIReturnKeyJoin
Set the text of the return key to “Join”.
Available in iPhone OS 2.0 and later.
Declared in UITextInputTraits.h.
UIReturnKeyNext
Set the text of the return key to “Next”.
Available in iPhone OS 2.0 and later.
Declared in UITextInputTraits.h.
UIReturnKeyRoute
Set the text of the return key to “Route”.
Available in iPhone OS 2.0 and later.
Declared in UITextInputTraits.h.
UIReturnKeySearch
Set the text of the return key to “Search”.
Available in iPhone OS 2.0 and later.
Declared in UITextInputTraits.h.
UIReturnKeySend
Set the text of the return key to “Send”.
Available in iPhone OS 2.0 and later.
Declared in UITextInputTraits.h.
UIReturnKeyYahoo
Set the text of the return key to “Yahoo”.
Available in iPhone OS 2.0 and later.
Declared in UITextInputTraits.h.
UIReturnKeyDone
Set the text of the return key to “Done”.
Available in iPhone OS 2.0 and later.
Declared in UITextInputTraits.h.
UIReturnKeyEmergencyCall
Set the text of the return key to “Emergency Call”.
Available in iPhone OS 2.0 and later.
Declared in UITextInputTraits.h.
6、获取系统里面的当前时间
- - (NSDate *)getNowDateFromatAnDate:(NSDate *)anyDate
- {
- //设置源日期时区
- NSTimeZone* sourceTimeZone = [NSTimeZone timeZoneWithAbbreviation:@"UTC"];//或GMT
- //设置转换后的目标日期时区
- NSTimeZone* destinationTimeZone = [NSTimeZone localTimeZone];
- //得到源日期与世界标准时间的偏移量
- NSInteger sourceGMTOffset = [sourceTimeZone secondsFromGMTForDate:anyDate];
- //目标日期与本地时区的偏移量
- NSInteger destinationGMTOffset = [destinationTimeZone secondsFromGMTForDate:anyDate];
- //得到时间偏移量的差值
- NSTimeInterval interval = destinationGMTOffset - sourceGMTOffset;
- //转为现在时间
- NSDate* destinationDateNow = [[[NSDate alloc] initWithTimeInterval:interval sinceDate:anyDate] autorelease];
- return destinationDateNow;
- }
7、如何判断UIScrollView滑动方向?
static float newIx;
static float oldIx;
然后在声明Scrollview的地方给这2个变量初始值,比方说我给的是Scrollview的最后一页内容
附代码
#pragma mark - UIScrollView Delegate
-(void)scrollViewDidEndDecelerating:(UIScrollView*)scrollView{//当上面提到的减速完毕、滚动视图停止时得到通知。收到这个通知的时刻,滚动视图的contentOffset属性会反映出滚动条最终停止的位置。
self.userContentSetOffX=scrollView.contentOffset.x;
self.currentTableview=[self.mainScrollview.subviews objectAtIndex:self.mainScrollview.contentOffset.x/kScreen_width];//得到当前的Tableview
// static float newx = 0;
// static float oldIx = 0;
newIx= scrollView.contentOffset.x ;
if (newIx != oldIx) {
//Left-YES,Right-NO
if (newIx > oldIx) {
[self right_changeDateTishiLabelText];
self.scrollLeftOrRight = NO;
}else if(newIx < oldIx){
[self left_changeDateTishiLabelText];
self.scrollLeftOrRight = YES;
}
oldIx = newIx;
}
/*更改导航条上的日期标签*/
}
8、日期选取器显示的数据设置为国式
UIDatePicker *pic = (UIDatePicker *)[dataChoosePickerView viewWithTag:3];
NSDateFormatter *formatter=[[NSDateFormatter alloc]init];
[formatter setDateFormat: @"yyyy-MM-dd"];
NSDate *date = pic.date;
NSLocale *locale=[[NSLocale alloc]initWithLocaleIdentifier:@"zh_CN"];
pic.locale=locale;
self.birthday.text = [formatter stringFromDate:date ];
9、iOS英文—》汉化,如调用相本,相机改“cancel”,“photos”为“取消”,“相机”
只需要改三个地方:
1、plist文件中:
2、info里面-->Custom iOS Target Properites
3、info-->Localizations
至此ok。
8、tableview的分割线离边框总是短了一截
if ([self.tableView respondsToSelector:@selector(setSeparatorInset:)]) {
[self.tableView setSeparatorInset:UIEdgeInsetsZero];
}
9、按钮显示秒的信息
sender.titleLabel.text =[NSString stringWithFormat:@"%@秒",strTime];
10、按钮显示秒的信息
隐藏视图中的左侧按钮 self.navigationItem.hidesBackButton=YES;(界面2的返回标题需要在界面1设置,但是隐藏界面2的返回按钮,就要再界面2设置)
10、按钮居左显示
[back setContentHorizontalAlignment:UIControlContentHorizontalAlignmentLeft];
- (void)customBackBarButtonItemWithTitle:(NSString *)title
{
CGSize size;
if (HXUtils->iOS7Version()) {
size = [title sizeWithAttributes:@{NSFontAttributeName : [UIFont fontWithName:@"Helvetica" size:15]}];
} else {
size = [title sizeWithFont:[UIFont fontWithName:@"Helvetica" size:14] constrainedToSize:CGSizeMake(MAXFLOAT, MAXFLOAT)];
}
UIButton *backBtn = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, 44 + size.width, 44)];
[backBtn setImage:[UIImage imageNamed:@"btn_back"] forState:UIControlStateNormal];
[backBtn setTitle:title forState:UIControlStateNormal];
[backBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
[backBtn addTarget:self action:@selector(backBarButtonItemClick:) forControlEvents:UIControlEventTouchUpInside];
[backBtn setExclusiveTouch:YES];
UIBarButtonItem *backBarItem = [[UIBarButtonItem alloc] initWithCustomView:backBtn];
backBarItem.tintColor = [UIColor clearColor];
[self.navigationItem addLeftBarButtonItem:backBarItem];
}
IOS中 NSDictionary无序字典排序
按NSDictionary的key来对其进行排序:
先将dict的allkeys赋给一个数组,然后通过sortedArrayUsingComparator:方法对数组排序,然后遍历数组取字典对应key的值就ok
NSArray *keys = [dict allKeys];
NSArray *sortedArray = [keys sortedArrayUsingComparator:^NSComparisonResult(idobj1, id obj2) {
return [obj1 compare:obj2 options:NSNumericSearch];
}];
for (NSString *categoryId in sortedArray) {
⋯⋯
NSLog(@"[dict objectForKey:categoryId] === %@",[dictobjectForKey:categoryId]);
}
方法二:
NSString *filePath = [[NSBundle mainBundle]pathForResource:@"students" ofType:@"plist"];
NSDictionary *stuDic = [NSDictionary dictionaryWithContentsOfFile:filePath];
self.studentIndexArray = [NSMutableArray arrayWithCapacity:1];
NSArray *arr = [[stuDic allKeys] sortedArrayUsingSelector:@selector(compare:)];
svn中
UserInterfaceState.xcuserstate 文件频繁更新,*.a等静态链接库文件默认不被添加到 SVN 中,需要对自己 Mac OS 上的 SVN 客户端配置做一下修改。
前往文件夹:
~/.subversion/config
查找 [miscellany] 字段
在默认被注释的 global-ignores 下一行,增加一行:
global-ignores = *~ #*# .#* .*.swp .DS_Store .xcuserstate
ios7以下的版本设置导航栏背景颜色可以使用
[[UINavigationBar appearance] setTintColor:[UIColor orangeColor]];
ios7以后:
[[UINavigationBar appearance] setBarTintColor:[UIColor orangeColor]];