ios 杂乱小总结

来源:互联网 发布:ping 端口号 编辑:程序博客网 时间:2024/05/17 03:57

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、由于首级视图标题太长了,然后我就想在第一级界面引用第二级界面的时候设置二级界面的返回按钮的Title

然后就使用了


ViewController *vc=[ViewController alloc]init];

vc.navigationController.navigationController.navigationItem.backBarButtonItem.title=@"返回";

发现根本就不管用,后来查阅资料就解决了:


 UIBarButtonItem *BarButtonItem= [[UIBarButtonItem allocinit];

    BarButtonItem.title @"返回";

    self.navigationItem.backBarButtonItem =BarButtonItem;



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、获取系统里面的当前时间

  1. - (NSDate *)getNowDateFromatAnDate:(NSDate *)anyDate  
  2. {  
  3.     //设置源日期时区  
  4.     NSTimeZone* sourceTimeZone = [NSTimeZone timeZoneWithAbbreviation:@"UTC"];//或GMT  
  5.     //设置转换后的目标日期时区  
  6.     NSTimeZone* destinationTimeZone = [NSTimeZone localTimeZone];  
  7.     //得到源日期与世界标准时间的偏移量  
  8.     NSInteger sourceGMTOffset = [sourceTimeZone secondsFromGMTForDate:anyDate];  
  9.     //目标日期与本地时区的偏移量  
  10.     NSInteger destinationGMTOffset = [destinationTimeZone secondsFromGMTForDate:anyDate];  
  11.     //得到时间偏移量的差值  
  12.     NSTimeInterval interval = destinationGMTOffset - sourceGMTOffset;  
  13.     //转为现在时间  
  14.     NSDate* destinationDateNow = [[[NSDate alloc] initWithTimeInterval:interval sinceDate:anyDate] autorelease];  
  15.     return destinationDateNow;  


7、如何判断UIScrollView滑动方向?

首先在你的声明文件里面定义2个静态变量

static float newIx;
static float oldIx;

然后在声明Scrollview的地方给这2个变量初始值,比方说我给的是Scrollview的最后一页内容


最后在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]];


持续更新中。。。。






 

0 0
原创粉丝点击