oc实用疑难杂症解决方法ios开发小技巧
发布日期:2021-06-20 03:26:07 浏览次数:4 分类:技术文章

本文共 6898 字,大约阅读时间需要 22 分钟。

 

1.self.edgesForExtendedLayout =  UIRectEdgeBottom ; //

2.model中id属性解决方法:

在controller中添加 :

[OrderModel mj_setupReplacedKeyFromPropertyName:^NSDictionary *{

        return @{@"ID":@"id"};

    }];

3.跳转tabbar控制页面: self.tabBarController.selectedIndex = 1;

4.tableview section悬停问题解决: UITableViewStyleGrouped

    self.tableView.estimatedRowHeight = 0;

    self.tableView.estimatedSectionHeaderHeight = 0;

    self.tableView.estimatedSectionFooterHeight = 0;

    self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;隐藏分割线

- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section {

    return CGFLOAT_MIN;

}

5.打电话弹窗:

dispatch_async(dispatch_get_main_queue(), ^{

               UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"拨打客服" message:@"客服的服务时间为\n 9:00 -  20:00" preferredStyle:(UIAlertControllerStyleAlert)];

                UIAlertAction *confirm = [UIAlertAction actionWithTitle:@"拨号" style:(UIAlertActionStyleDefault) handler:^(UIAlertAction * _Nonnull action) {

                    NSString *callPhone = [NSString stringWithFormat:@"telprompt://%@", self.phone];

                    NSComparisonResult compare = [[UIDevice currentDevice].systemVersion compare:@"10.0"];

                    dispatch_async(dispatch_get_main_queue(), ^{

                        if (compare == NSOrderedDescending || compare == NSOrderedSame) {

                            [[UIApplication sharedApplication] openURL:[NSURL URLWithString:callPhone]];

                        }else{

                            [[UIApplication sharedApplication] openURL:[NSURL URLWithString:callPhone]];

                        }

                    });

                }];

                UIAlertAction *cancel = [UIAlertAction actionWithTitle:@"取消" style:(UIAlertActionStyleCancel) handler:nil];

                [alert addAction:confirm];

                [alert addAction:cancel];

                [self.viewController presentViewController:alert animated:YES completion:nil];

            });

6.时间戳转换:

- (NSString *)getTimeFromTimesTamp:(NSString *)timeStr

{

    double time = [timeStr doubleValue];

    NSDate *myDate = [NSDate dateWithTimeIntervalSince1970:time];

    NSDateFormatter *formatter = [NSDateFormatter new];

    [formatter setDateFormat:@"YYYY-MM-dd HH:mm:ss"];

    //将时间转换为字符串

    NSString *timeS = [formatter stringFromDate:myDate];

    return timeS;

}

7.imageview添加手势:

self.headerImg.userInteractionEnabled = YES;

UITapGestureRecognizer *tapGesture = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(clickRegistrationAgreementBtn)];

    [self.headerImg addGestureRecognizer:tapGesture];

8.imageview添加边框: self.headerImg.layer.borderColor = [YJUIColorRGB(67, 64, 63) CGColor];

                    self.headerImg.layer.borderWidth = 5.0f;

               圆角: self.headerImg.layer.masksToBounds = YES;

                     self.headerImg.layer.cornerRadius = 30;

 

9.label文字设置:

 NSMutableAttributedString *attributedString = [[NSMutableAttributedString alloc] initWithString:[NSString stringWithFormat:@"确认收货并转卖 可得%@现金返利",model.fee_rate]];

    [attributedString addAttribute:NSForegroundColorAttributeName value:[UIColor colorWithRed:119.0f/255.0f green:119.0f/255.0f blue:119.0f/255.0f alpha:1.0f] range:NSMakeRange(0, 10)];

    [attributedString addAttribute:NSForegroundColorAttributeName value:[UIColor colorWithRed:243.0f/255.0f green:194.0f/255.0f blue:108.0f/255.0f alpha:1.0f] range:NSMakeRange(10, 3)];

    [attributedString addAttribute:NSForegroundColorAttributeName value:[UIColor colorWithRed:119.0f/255.0f green:119.0f/255.0f blue:119.0f/255.0f alpha:1.0f] range:NSMakeRange(13, 4)];

_grayLabel.attributedText = attributedString;

 

10.label添加长按手势复制功能:        

_grayLabel.userInteractionEnabled = YES;

UILongPressGestureRecognizer * longPressGr = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(longPre:)];

[_grayLabel addGestureRecognizer:longPressGr];

 

- (BOOL)canBecomeFirstResponder{

    return YES;

}

// 可以控制响应的方法

- (BOOL)canPerformAction:(SEL)action withSender:(id)sender{

    return (action == @selector(copy:));

}

// 处理长按事件

- (void)longPre:(UILongPressGestureRecognizer *)recognizer{

    [self becomeFirstResponder]; // 用于UIMenuController显示,缺一不可

    //UIMenuController:可以通过这个类实现点击内容,或者长按内容时展示出复制等选择的项,每个选项都是一个UIMenuItem对象

    UIMenuItem *copyLink = [[UIMenuItem alloc] initWithTitle:@"复制" action:@selector(copy:)];

    [[UIMenuController sharedMenuController] setMenuItems:[NSArray arrayWithObjects:copyLink, nil]];

    [[UIMenuController sharedMenuController] setTargetRect:self.grayLabel.frame inView:self.grayLabel.superview];

    [[UIMenuController sharedMenuController] setMenuVisible:YES animated:YES];

}

-(void)copy:(id)sender{

    UIPasteboard *pboard = [UIPasteboard generalPasteboard];

    pboard.string = self.grayLabel.text;

 [LEPProgressHUD showSuccess:@"复制成功"];

}

 

11.置顶: 

-(void)viewWillAppear:(BOOL)animated{

    [super viewWillAppear:animated];

    [self.mTableView setContentOffset:CGPointMake(0,0) animated:NO];

}

12.代码混淆  

    1.bundle id

    2.项目名称

    3.类名

    4.本地文件夹名字

    5.项目目录名字

    6.文件顶部注释

    7.加垃圾属性

    8.垃圾属性的调用

    9.方法增加稍微长点前缀

13.单元测试

14.新添加的苹果账号需要重新从钥匙串申请证书、申请开发者证书

15.xcode搜索区分大小写

16.coding使用

 

17.label设置不同颜色字体大小

UILabel *agreementLabel =[[UILabel alloc]init];

    agreementLabel.textAlignment = NSTextAlignmentCenter;

    agreementLabel.font =[UIFont systemFontOfSize:11];

    agreementLabel.userInteractionEnabled = YES;

    agreementLabel.textColor = YJUIColorHex(@"#acacac");

    NSMutableAttributedString *ms = [[NSMutableAttributedString alloc] initWithString:@"您已同意" attributes:@{NSForegroundColorAttributeName:YJUIColorRGB(170, 170, 170),NSFontAttributeName:[UIFont systemFontOfSize:11]}];

    [ms appendAttributedString:[[NSAttributedString alloc] initWithString:@"《淘福利用户协议》" attributes:@{NSForegroundColorAttributeName:YJUIColorRGB(67, 64, 63),NSFontAttributeName:[UIFont systemFontOfSize:11]}]];

    [agreementLabel setAttributedText:ms];

    [self.headerImg addSubview:agreementLabel];

    agreementLabel.sd_layout.centerXEqualToView(self.headerImg).bottomSpaceToView(self.headerImg, 25).widthIs(200).heightIs(17);

   

    UITapGestureRecognizer *tapGesture = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(agreementBtn)];

    [agreementLabel addGestureRecognizer:tapGesture];

18.系统cell

static NSString *CellIdentifier = @"Cell";

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];

   

    if (cell == nil) {

        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];

    }

   

    cell.textLabel.text = @"出发点";

    return cell;

19.model关键字 处理

[ProductModel mj_setupReplacedKeyFromPropertyName:^NSDictionary *{

        return @{@"ID":@"id"};

    }];

 

20.随机颜色

    cells.backgroundColor = [UIColor colorWithRed:((10 * indexPath.row) / 255.0) green:((20 * indexPath.row)/255.0) blue:((30 * indexPath.row)/255.0) alpha:1.0f];

 

22更改项目名 

 

23 返回指定页

self.tabBarController.selectedIndex = 0;

[self.navigationController popToRootViewControllerAnimated:NO];

AppDelegate *appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];

FLTabBarViewController *tabViewController = (FLTabBarViewController *) appDelegate.window.rootViewController;

[tabViewController setSelectedIndex:0];

 

24 键盘上的Done也会变成响应的中文

在project->info->Localizations添加chinese选项

25 按钮自适应

button.titleLabel.baselineAdjustment = UIBaselineAdjustmentAlignCenters;//垂直居中基准线button.titleLabel.adjustsFontSizeToFitWidth = YES;

待续。。

转载地址:https://blog.csdn.net/Fu_Tong/article/details/88739696 如侵犯您的版权,请留言回复原文章的地址,我们会给您删除此文章,给您带来不便请您谅解!

上一篇:苹果内购退款问题
下一篇:tableview section悬停问题解决: UITableViewStyleGrouped

发表评论

最新留言

初次前来,多多关照!
[***.217.46.12]2024年04月05日 09时11分15秒