- 博客(8)
- 资源 (1)
- 收藏
- 关注
转载 iOS 长按手势
1、viewDidLoad中 //按住录音按钮添加长按手势 UILongPressGestureRecognizer *longPressGesture = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(longPress:)]; [self.longPressBtn addGestureRecognizer:longPressGesture]; 2、//长按录音 -(void)longPress:(
2021-01-23 15:31:17
509
转载 iOS给UILabel设置内边距
NSMutableParagraphStyle *style = [[NSParagraphStyle defaultParagraphStyle] mutableCopy]; style.alignment = NSTextAlignmentJustified; style.firstLineHeadIndent = 10.0f; style.headIndent = 10.0f; style.tailIndent = -10.0f; NSAttribu...
2021-01-16 14:15:30
2599
转载 iOS 判断当前网络状态的三种方法
在项目中,为了好的用户体验,有些场景必须线判断网络状态,然后才能决定改干嘛。比如视频播放,需要线判断是Wifi还是4G,Wifi直接播放,4G先提示用户。获取网络状态的方法大概有三种: Reachability 这是苹果的官方演示demo中使用到的方法,我们可以到苹果官方文档里下载Demo(点击左上角Download Sample Code 即可下载),然后把Demo里的Reachability.h和.m考到自己项目中,并在Build Phases 的 Link Binary 添加SystemConfi
2021-01-09 15:03:41
740
原创 iOS开发:判断iPhone是否是刘海屏iPhoneX、iPhoneXR、iPhoneXs、iPhoneXs Max等
Objective-C // iPhoneX、iPhoneXR、iPhoneXs、iPhoneXs Max等 // 判断刘海屏,返回YES表示是刘海屏 - (BOOL)isNotchScreen { if ([UIDevice currentDevice].userInterfaceIdiom == UIUserInterfaceIdiomPad) { return NO; } CGSize size = [UIScreen mainScreen]
2021-01-09 14:58:02
1012
转载 iOS使用UICollectionView只允许向左方向滑动,不允许向右方向滑动。
- (void)scrollViewDidScroll:(UIScrollView *)scrollView { if (scrollView == 《这里换成你的UICollocView子类》) { //禁止右划 static float newx = 0; static float oldx = 0; newx= scrollView.contentOffset.x ; if (newx < oldx) {
2020-12-26 14:06:19
1849
原创 iOS 强制屏幕实现旋转功能
1.创建工程,设置Device Orientation 2.在AppDelegate中实现下面这个方法: - (UIInterfaceOrientationMask)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window { if (self.allowRotation) { return UIInterfaceOrientationMas
2020-12-18 08:53:38
2273
3
转载 iOS 监听控件某个属性的改变observeValueForKeyPath
创建一个测试的UIButton #import "ViewController.h" @interface ViewController () @property(nonatomic, strong)UIButton *button; @end @implementation ViewController - (void)viewDidLoad { [super viewDidLoad]; self.button = [[UIButton alloc] initWithF
2020-12-12 13:34:52
1422
原创 OS开发 UIWebView与JavaScript交互
iOS原生应用与Web页面元素交互方式有很多,JavaScriptCore、拦截协议、第三方框架WebViewJavaScriptBridge、iOS8之后的WKWebView等; 简要记录下之前开发用到的两种方式: 拦截页面加载,从 UIWebVIew 的 shouldStartLoadWithRequest 方法中拦截RequestURL 判断加载项,代码简要: -(BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURL
2020-12-05 08:22:37
177
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人