IOS开发日记

来源:互联网 发布:开淘宝网店难吗 编辑:程序博客网 时间:2024/06/04 18:47

2016.07.19

  • UILabel 在宽度固定的情况下,设置其根据文字长度调整字体:
@property (weak, nonatomic) IBOutlet UILabel *pinyName;self.pinyName.adjustsFontSizeToFitWidth = YES;
  • 弹出框

IOS 9.0 以前:

NSString *msg = @"something";UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"提示" message:msg delegate:self cancelButtonTitle:@"确定" otherButtonTitles:nil, nil];[alert show];

IOS 9.0 以后:

UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"提示" message:@"something" preferredStyle:UIAlertControllerStyleAlert];[alertController addAction:[UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {    // 响应事件}]];[self presentViewController:alertController animated:YES completion:nil];

2016.07.20

  • 根据内容调整UIView大小
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"psnChangeCell"];UILabel *textView = (UILabel *)[cell viewWithTag:17];textView.text = rowRecord.msg;CGSize s = [textView sizeThatFits:CGSizeMake([UIScreen mainScreen].bounds.size.width - 74, FLT_MAX)];
  • 从 storyboard 中加载 view controller 并显示
let mainStoryboard = UIStoryboard(name: "Main", bundle: nil)let registerViewController = mainStoryboard.instantiateViewControllerWithIdentifier("registerViewController")self.presentViewController(registerViewController, animated: false, completion: nil)
  • 使 UITextField 弹出的键盘为数字键盘
self.resultTextField.keyboardType = .NumberPad

2016.07.22

  • 禁止 UITableViewCell 向左滑动时显示删除按钮
- (UITableViewCellEditingStyle)tableView:(UITableView *)tableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath {    return UITableViewCellEditingStyleNone;}

2016.07.26

  • 自定义导航栏的标题
// 设置自定义标题栏,避免标题过长,返回按钮被遮盖的问题UIView *titleView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 200, 40)];UILabel *titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 200, 30)];[titleLabel setFont:[UIFont systemFontOfSize:17.0 weight:UIFontWeightMedium]];[titleLabel setTextColor:[UIColor whiteColor]];[titleLabel setCenter:titleView.center];[titleLabel setTextAlignment:NSTextAlignmentCenter];[titleLabel setAdjustsFontSizeToFitWidth:YES];[titleView addSubview:titleLabel];[self.navigationItem setTitleView:titleView];[titleLabel setText:self.title];self.titleLabel = titleLabel;
  • 去除UITableView底部多余的分割线
- (void)viewDidLoad{    [super viewDidLoad];    self.tableView.tableFooterView = [[UIView alloc] initWithFrame:CGRectZero];}

2016.07.29

  • Observer模式应用
// 添加Observer[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(reloadFCL) name:@"reloadFCL" object:nil];// 删除Observer- (void)dealloc {    [[NSNotificationCenter defaultCenter] removeObserver:self];}// 发送消息,userInfo是一个Dictionary[[NSNotificationCenter defaultCenter] postNotificationName:@"reloadFCL" object:nil userInfo:nil];
  • 屏蔽手势滑动返回功能
- (void)viewWillAppear:(BOOL)animated{    // 屏蔽手势返回功能    if ([self.navigationController respondsToSelector:@selector(interactivePopGestureRecognizer)]) {        self.navigationController.interactivePopGestureRecognizer.enabled = NO;    }}- (void)viewWillDisappear:(BOOL)animated{    [super viewWillDisappear:YES];    // 开启手势返回功能    if ([self.navigationController respondsToSelector:@selector(interactivePopGestureRecognizer)]) {        self.navigationController.interactivePopGestureRecognizer.enabled = YES;    }}

2016.08.02

  • 设置UILabel当text过长时以省略号结尾
[titleLabel setLineBreakMode:NSLineBreakByTruncatingTail];

2016.08.03

  • 隐藏导航栏
[self.navigationController setNavigationBarHidden:YES];

2016.08.04

  • 隐藏UIViewController底部导航栏
[controller setHidesBottomBarWhenPushed:YES];[self.navigationController pushViewController:controller animated:YES];

2016.08.24

  • 隐藏系统状态栏,顶部带电池的那个栏
- (BOOL)prefersStatusBarHidden {    return YES;}
  • 显示等待窗口
// 定义 indicatorView 和 indicatorLabel@property (strong, nonatomic) UIActivityIndicatorView* indicatorView;@property (strong, nonatomic) UILabel* indicatorLabel;// 初始化self.indicatorView = [[UIActivityIndicatorView alloc] initWithFrame:CGRectMake(0, 0, 30, 30)];self.indicatorView.center = self.view.center;self.indicatorView.frame = self.view.frame;self.indicatorView.backgroundColor = [UIColor blackColor];self.indicatorView.alpha = 0.75;self.indicatorView.activityIndicatorViewStyle = UIActivityIndicatorViewStyleWhiteLarge;[self.view addSubview:self.indicatorView];self.indicatorLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 250, 30)];self.indicatorLabel.textColor = [UIColor whiteColor];self.indicatorLabel.textAlignment = NSTextAlignmentCenter;self.indicatorLabel.text = @"正在加载会议列表,请稍候...";self.indicatorLabel.center = CGPointMake(self.view.center.x, self.view.center.y + 40);[self.view addSubview:self.indicatorLabel];// 显示&隐藏[self.indicatorView startAnimating];self.indicatorLabel.hidden = NO;

2016.09.08

  • URL打开app
    1. 首先被启动的应用需要向iPhone注册一个自定义URL协议。这是在你的项目文件夹的info.plist文件进行的(就是你改变应用程序图标的同一个文件)。
    2. 右键,选择“Add Row”
    3. Key值选择“URL types”
    4. 打开“Item 0″,然后为该key增加一个URL identifier。可以是任何值,但建议用“反域名”(例如 “com.cynhard.LinphoneTest”)。
    5. 在“Item 0”下再加一行。
    6. 选择“URL Schemes” 作为Key。
    7. 输入你的URL协议名 (例如“testHello://” 应写做“testHello”)。如果有必要,你可以在这里加入多个协议。
    8. 访问URL:
<!DOCTYPE html><html>    <head>        <title>Hello World</title>    </head>    <body>        <a href="LinphoneTest://">test</a>    </body></html>

2016.09.09

  • 使用lipo命令合成静态库
lipo -create Release-iphoneos/libMyToolsA.a Release-iphonesimulator/libMyToolsA.a -output libMyToolsA.a
  • 查看库的信息
lipo -info libMyToolsA.a
0 0