
iOS
LevelBe
自己开心就好
展开
-
iOS 开发检测是否开启定位、是否允许消息推送等权限
1、检测是否开启定位:需要导入:#import <CoreLocation/CoreLocation.h>代码如下:if ([CLLocationManager locationServicesEnabled] && [CLLocationManager authorizationStatus] != kCLAuthorizationStatusDe...转载 2020-07-27 16:18:52 · 1364 阅读 · 0 评论 -
iOS 为了使AlertContrller在视图的最上面,故添加到Window层上
UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"获取相册提示"message:@"开启相册提示"preferredStyle:UIAlertControllerStyleAlert]; UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:@"取消"style:UIAlertActionStyle...原创 2020-07-23 10:00:10 · 1107 阅读 · 0 评论 -
iOS storyboard 与 xib 间相互跳转
项目结构storyboard 跳转到 xibrestaurantViewController *vc = [[restaurantViewController alloc] initWithNibName:@"restaurantViewController" bundle:[NSBundle mainBundle]];[self presentViewController:vc animated:YES completion:^{ NSLog(@"进入");}];xib 跳转原创 2020-06-11 17:22:30 · 506 阅读 · 0 评论 -
iOS Xcode 11 的变化
仅目前发现的,有不足之处,希望小伙伴留言评论。1、User Interface 项可选择 SwiftUI 和 Storyboard。2、在选择 Swift 或Storyboard 后系统会自动增加SceneDelegate类。此时如果删除ScenDelegate类,运行后出现黑屏、报错:错误一:Info.plist configuration "(no name)" for UIWindowSceneSessionRoleApplication contained UIScen.原创 2020-06-08 17:37:40 · 1659 阅读 · 0 评论 -
iOS 图片上传时压缩处理
在上传图片时,如果对图片内存大小有要求,需上传前进行压缩处理,这样服务器也会减少压力。接下来我们正式开始:1、先对图片进行“压”操作,降低图片的分辨率,宽高不会改变。2、如果还不能满足要求,则在“压”的基础上,再对图片进行“缩”操作,改变图片的宽高。直接从相机,相册Finish的代理开始#pragma mark - UIImagePickerController Delegate- (void)imagePickerController:(UIImagePickerContro.转载 2020-06-03 17:31:37 · 899 阅读 · 0 评论 -
iOS webview 退出页面后视频/音频依旧播放的问题
首先在初始化 webview 前先注入网页停止播放音乐的 js 代码。WKWebViewConfiguration *config = [[WKWebViewConfiguration alloc] init];config.allowsInlineMediaPlayback = YES;config.requiresUserActionForMediaPlayback = NO; ...原创 2020-05-08 14:33:52 · 4271 阅读 · 2 评论 -
iOS 开发中的日期格式
NSDateFormatterG:公元时代, 例如AD公元yy:年后的2位yyyy:完整年MM:月,显示为1-12MMM:月,显示为英文月分简写,如: JanMMMM:月, 显示为英文月分全称,Julydd:日, 2位数表示,如02d:日,1-2位显示, 如2EEE: 简写星期几,如SunEEEE:全写星期几,如Sundayaa:上下午,AM/PM...原创 2020-04-23 15:25:48 · 1429 阅读 · 0 评论 -
iOS ContentCompressionResistancePriority和ContentHuggingPriority
抗压缩(不想变小约束)setContentCompressionResistancePriority抗拉伸(不想变大约束)setContentHuggingPriority约束优先级:在 Autolayout 中每个约束都有一个优先级, 优先级的范围是1 ~ 1000。创建一个约束,默认的优先级是最高的1000Content Hugging Priority:该优先级...原创 2020-04-22 15:54:47 · 1492 阅读 · 0 评论 -
iOS userInteractionEnabled 和 editable 的区别
首先userInteractionEnabled是UIView类中的一个属性。enabled是UIControl类中的一个属性。UIControl继承于UIView。如果设置userInteractionEnabled为NO,点击方法或者触摸事件之类事件会穿透视图。而设置enabled为NO会禁止该控件的交互,并且事件不会穿透。...转载 2020-04-22 11:39:52 · 515 阅读 · 0 评论 -
WKWebView 网页缓存和刷新
现象描述由于后台更新了一个网页,但iOS这边显示的还是旧内容。此现象 ——网页的缓存WKWebView的缓存策略typedef NS_ENUM(NSUInteger, NSURLRequestCachePolicy){ NSURLRequestUseProtocolCachePolicy = 0, // 默认策略,具体的缓存逻辑和协议的声明有关,如果协议没有声明,不需要每次重...转载 2020-04-08 15:59:11 · 4887 阅读 · 0 评论 -
Xcode Simulator无法安装,提示The com.apple.CoreSimulator.SimRuntime.XXX simulator runtime is not available
在下载其他系统的模拟器安装成功后,运行时提示以下内容.runtime profile not foundDownload the com.apple.CoreSimulator.SimRuntime.iOS-12-4 simulator runtime from the Components section in Xcode's Preferences.这是由于没有文件权限导致的。...原创 2019-12-13 11:42:48 · 3124 阅读 · 0 评论 -
iOS 随机数:rand()、random()、arc4random() 方法
一、iphone有几个内嵌的随机数发生器,如rand()、random()、arc4random()其精确程度为arc4random() > random() > rand()可以由其原型进行推断int rand();long random();u_int32_t arc4random();二、rand()和random()在使用之前需要先初...转载 2019-12-10 09:29:05 · 1638 阅读 · 0 评论 -
苹果开发者账号变更公司名称
可能少部分人会遇到公司名称更名的问题,接下来将我更名的流程整理出来。1、首先要和苹果技术支持,点击此链接https://developer.apple.com/contact/,选择会员资格与帐户->组织名称更改,输入联系你的电话(可以是非申请人的电话),等待技术支持的交谈。接通后需要说明你账号的持有人姓名,再说明你的需求,随后苹果技术支持会发申请流程的邮件给你。2、点击此链...原创 2019-12-04 11:04:55 · 12598 阅读 · 1 评论 -
WKWebView 允许跳转到 App Store
获取AppStore 中应用的下载地址(xxxxxxxxxx 是应用在App Store中的apple id)itms-apps://itunes.apple.com/cn/app/idxxxxxxxxxx?mt=8app 检测更新(xxxxxxxxxx 是应用在App Store中的apple id)NSString *itunesUrl = @"http://itunes.ap...原创 2019-11-30 13:42:02 · 2180 阅读 · 0 评论 -
Xcode Localizations Change Development Language (Xcode 本地化 修改默认的开发语言)
应用程序默认的开发语言是英语,一般使用的简体中文,怎么把默认的开发语言改成中文呢?现在默认显示的是English点击+号添加中文简体找到 info.plist 的 Localization Native Development Region把 en 改为zh-Hans关闭 Xcode,找到该项目的 .xcodeproj 文件,右键显示包内容用文本编辑器打...转载 2019-11-29 17:37:59 · 5321 阅读 · 0 评论 -
iOS UIButton中调整image大小
UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];[_button setImage:[UIImage imageNamed:@"right_arrow"] forState:UIControlStateNormal];///调整图片大小[_button setImageEdgeInsets:UIEdgeIns...原创 2019-10-30 15:42:55 · 9851 阅读 · 1 评论 -
iOS dispatch_sync(dispatch_get_main_queue(), ^{ });死锁的原因
- (void)viewDidLoad { dispatch_sync(dispatch_get_main_queue(), ^{ NSLog(@1); //死锁原因 //1:dispatch_sync 在等待 block 语句执行完成,而 block 语句需要在主线程里执行,所以dispatch_sync如果在主线程调用就会造成死锁 ...原创 2019-10-17 16:10:01 · 2552 阅读 · 0 评论 -
tableView 解决加载数据混乱问题
-(UITableViewCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{ NSString *flag = @"cell"; UITableViewCell *cell = [tableView dequeueReusableCellWithId原创 2015-08-08 14:32:49 · 2099 阅读 · 0 评论 -
去掉搜索框(searchBar)的背景框
使用iOS系统自带的searchBar。_searchBar = [UISearchBar new];_searchBar.placeholder = @"输入您想查询的内容";_searchBar.delegate = self;[self.view addSubview:_searchBar];[_searchBar mas_makeConstraints:^(MASConstr...原创 2018-09-14 10:06:13 · 1537 阅读 · 0 评论 -
上传图片
// 上传头像NSString*url = [NSStringstringWithFormat:@"%@?requestflag=upheads",kPostUrl];NSMutableURLRequest* request = [NSMutableURLRequestrequestWithURL:[NSURLURLWithString:url]];request.HTTPMe...原创 2016-09-29 09:03:00 · 373 阅读 · 0 评论 -
iOS 修改为http协议
iOS9后系统默认的是https协议,https和http的区别就是安全性修改为http协议的方法是:1、打开项目的plist文件找到Info;2、找到Application requires iPhone environment;3、添加Allow Arbitrary Loads 并设置为YES。...原创 2015-12-03 11:22:10 · 1032 阅读 · 0 评论 -
iOS 强制使用系统键盘
在 appDelegate.m 中- (BOOL)application:(UIApplication *)applicationshouldAllowExtensionPointIdentifier:(NSString *)extensionPointIdentifier{if ([extensionPointIdentifier isEqualToString:@"...原创 2016-07-02 19:49:13 · 887 阅读 · 0 评论 -
在cell上添加长按手势,并给手势添加tag值
1、在cell上添加长按手势;UILongPressGestureRecognizer *longPressGR = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(longPress:)];longPressGR.minimumPressDuration = 0.5;[cell add...原创 2016-07-02 09:00:48 · 1854 阅读 · 0 评论 -
iOS UIWebView 加载网页
#import "webViewController.h"#define UISCREEN_WIDTH [[UIScreen mainScreen]bounds].size.width#define UISCREEN_HEIGHT [[UIScreen mainScreen]bounds].size.height@interface webViewController ()@en...原创 2015-12-11 15:27:50 · 494 阅读 · 0 评论 -
Main Thread Checker: UI API called on a background thread
在开发的过程中遇到一个警告问题,如下:Main Thread Checker: UI API called on a background thread: -[UIWebView loadRequest:]PID: 18274, TID: 1210667, Thread name: (none), Queue name: com.apple.root.default-qos, QoS: 2...原创 2018-09-12 16:33:48 · 2161 阅读 · 0 评论 -
iOS 登录页面跳转到首页(含有tabBar)
自定义tabBar类在customTabBarCtrl.h中#import <UIKit/UIKit.h> @interface customTabBarCtrl : UITabBarController@end在customTabBarCtrl.m中#import "customTabBarCtrl.h"#import "mainViewContr...原创 2015-09-07 15:20:44 · 3174 阅读 · 0 评论 -
iOS 如何开启和关闭定时器
先在.h文件定义一个全局变量@property(nonatomic) NSTimer *timer;在.m文件中//定时器_timer = [NSTimer scheduledTimerWithTimeInterval:1 target:self selector:@selector(update) userInfo:nil repeats:YES];//关闭定时器[...原创 2015-09-06 16:59:03 · 1297 阅读 · 0 评论 -
定时器
在.h文件@property(nonatomic)UILabel *countDownLabel;@property(nonatomic)NSTimer *timer;@property(nonatomic,assign)int second;在.m文件- (void)viewDidLoad {_second = 120;原创 2015-09-06 16:49:03 · 462 阅读 · 0 评论 -
tableViewCell中图片下方的线不被遮挡
1、图片尺寸过大;2、设置-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView的个数;<img src="https://img-blog.youkuaiyun.com/20160104173948353?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQv/font...原创 2016-01-04 17:39:23 · 711 阅读 · 0 评论 -
使用tableView中的cell来实现单选效果
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{ NSArray *array = [tableView visibleCells]; for (UITableViewCell *cellin array) {// 不打对勾原创 2015-09-25 16:45:12 · 2972 阅读 · 0 评论 -
tableView 和聊天对话一样,显示最新的数据,不用滑动
在viewController.h文件中@property (nonatomic) NSInteger dataSource;@property (nonatomic) UITableView *chatTableView;在viewController.m文件中- (void)viewDidAppear:(BOOL)animated { [sup原创 2015-09-16 12:13:31 · 1007 阅读 · 0 评论 -
iOS tableView集成(上拉+下拉)刷新
#import"UIScrollView+MJRefresh.h"@interfacemainViewController()@property(strong,nonatomic)NSMutableArray*fakeData;@end@implementationmainViewController/***数据的懒加载*/- (NSMutab...原创 2015-08-08 15:32:19 · 688 阅读 · 0 评论 -
iOS tableView头部不动,cell滑动
思路:1、创建一个样式为plain的tableView; 2、返回多个section; 3、返回多个row; 4、设置tableHeadView的背景色(解决方法:在 -(UIView *)tableView:(UITableView *)tableView viewForHeaderIn...原创 2015-08-08 14:55:04 · 5538 阅读 · 0 评论 -
解决“同一UIView中有多个UITableView时点击状态栏不能置顶”问题
系统自带的点击状态栏是会置顶。如果UI View中有两个或两个以上 tableView,再点击状态栏不会置顶,由于多个 tableView 间会有冲突,所以要判断点击状态栏哪个tableView要置顶。talbeView1.scrollsToTop = NO;tableView2.scrollerToTop = YES;原创 2015-08-08 14:36:52 · 894 阅读 · 0 评论 -
根据按钮的状态来修改图片
UIButton *keepPWD = [UIButton buttonWithType:UIButtonTypeCustom];keepPWD.frame = CGRectMake(5, 390, 20, 20);[keepPWD setImage:[UIImage imageNamed:@"jzmm1.png"] forState:UIControlStateNormal];keepPW原创 2015-12-03 09:30:53 · 530 阅读 · 0 评论 -
button上的图片显示蓝色
UIButton *headImg = [UIButtonbuttonWithType:UIButtonTypeCustom];headImg.frame =CGRectMake((UISCREEN_WIDTH-60)/2,5, 60, 60);[headImgsetImage:[UIImageimageNamed:@"我的.png"]forState:UI原创 2015-09-01 15:05:35 · 1462 阅读 · 0 评论 -
button上设置图片
平时给button设置图片时一般会用setBackgroundImage:forState:方法,但是使用这个方法图片将会变形。现在终于解决了这个问题,使用下面这个方法,图片会自适应button。UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];[button setImage:[UIIm原创 2015-08-08 14:57:42 · 1245 阅读 · 0 评论 -
UIButton的实现(含有边框)
UIButton *reg = [UIButtonbuttonWithType:UIButtonTypeSystem];reg.frame = CGRectMake((UISCREEN_WIDTH-280)/2, mainView.frame.size.height-120, 280, 35);reg.layer.masksToBounds = YES;reg.layer.原创 2015-08-08 14:28:42 · 1240 阅读 · 0 评论 -
导航栏+tabBar的使用
UITabBarController *tabBarCtrl = [[UITabBarController alloc]init];tabBarCtrl.tabBar.backgroundColor = [UIColor whiteColor]; tabBarCtrl.tabBar.tintColor = [UIColor colorWithRed:30/225.0 green:23...原创 2015-08-08 09:33:16 · 871 阅读 · 0 评论 -
iOS 本地推送
appdelegete.m- (void)applicationDidBecomeActive:(UIApplication *)application { [[UIApplication sharedApplication] setApplicationIconBadgeNumber:0];//取消徽章}// 本地通知回调函数,当应用程序在前台时调用- (voi...原创 2015-08-08 14:50:10 · 479 阅读 · 0 评论