首页 文章 精选 留言 我的

精选列表

搜索[ios],共10000篇文章
优秀的个人博客,低调大师

ios xcode如何在控制台打印frame

进入正题 打开终端输入三条命令: 1. touch ~/.lldbinit 2. echo display @import UIKit >> ~/.lldbinit 3. echo target stop-hook add -o \"target stop-hook disable\" >> ~/.lldbinit 输完命令后没有任何提示? 好吧, 那恭喜你成功了~! 然后, 最关键的一步来了, 那就是… 重新运行项目(不用重启Xcode也可以),看如下图~~ 重新运行项目(不用重启Xcode也可以),看如下图~~ 就代表成功啦 那么现在我们继续在控制台输入po self.view.frame 成功了!如果po指令是一个id类型也可以正常打印。是不是感觉方便很多呀? 反正我是这么觉得。至于有没有用就看个人需要咯~~! 如何删除? 好吧, 那么问题来了, 我用命令创建, 如果不想玩了怎么办尼?? 其实很简答, 看第一条命令touch ~/.lldbinit,就是在根目录下创建了一个隐藏文件.lldbinit,然后删除这个文件就搞定啦。 打开终端然后,在终端输入 :?rm ~/.lldbinit 命令即可.

优秀的个人博客,低调大师

iOS - Quartz 2D 下载进度按钮绘制

1、绘制下载进度按钮 具体实现代码见 GitHub 源码 QExtension QProgressButton.h @interface QProgressButton : UIButton /// 进度值,范围 0 ~ 1 @property (nonatomic, assign) CGFloat progress; /// 进度终止状态标题,一旦设置了此标题进度条就会停止 @property (nonatomic, strong) NSString *stopTitle; /** * 创建带进度条的按钮 * * @param frame 按钮的 frame 值 * @param title 进按钮的标题 * @param lineWidth 进度条的线宽,default is 2 * @param lineColor 进度条线的颜色,default is greenColor * @param textColor 进度值的颜色,default is blackColor * @param backColor 按钮的背景颜色,default is clearColor * @param isRound 按钮是否显示为圆形,default is YES * * @return 带进度条的按钮 */ + (instancetype)q_progressButtonWithFrame:(CGRect)frame title:(NSString *)title lineWidth:(CGFloat)lineWidth lineColor:(nullable UIColor *)lineColor textColor:(nullable UIColor *)textColor backColor:(nullable UIColor *)backColor isRound:(BOOL)isRound; @end QProgressButton.m @interface QProgressButton () /// 进度条的线宽 @property (nonatomic, assign) CGFloat lineWidth; /// 进度条线的颜色 @property (nonatomic, strong) UIColor *lineColor; /// 按钮的背景颜色 @property (nonatomic, strong) UIColor *backColor; /// 按钮是否显示为圆形 @property (nonatomic, assign, getter=isRound) BOOL round; @end @implementation QProgressButton /// 创建带进度条的按钮 + (instancetype)q_progressButtonWithFrame:(CGRect)frame title:(NSString *)title lineWidth:(CGFloat)lineWidth lineColor:(nullable UIColor *)lineColor textColor:(nullable UIColor *)textColor backColor:(nullable UIColor *)backColor isRound:(BOOL)isRound { QProgressButton *progressButton = [[self alloc] init]; progressButton.lineWidth = lineWidth ? : 2; progressButton.lineColor = lineColor ? : [UIColor colorWithRed:76/255.0 green:217/255.0 blue:100/255.0 alpha:1.0]; progressButton.backColor = backColor ? : [UIColor clearColor]; progressButton.round = isRound; // 设置按钮的实际 frame if (isRound) { CGRect tmpFrame = frame; tmpFrame.origin.y = frame.origin.y - (frame.size.width - frame.size.height) * 0.5; tmpFrame.size.height = frame.size.width; progressButton.frame = tmpFrame; } else { progressButton.frame = frame; } // 设置显示的标题和颜色 [progressButton setTitle:title forState:UIControlStateNormal]; [progressButton setTitleColor:(textColor ? : [UIColor blackColor]) forState:UIControlStateNormal]; return progressButton; } /// 绘制进度条 - (void)drawRect:(CGRect)rect { // 设置按钮圆角 self.layer.masksToBounds = YES; self.layer.cornerRadius = rect.size.height * 0.5; // 绘制按钮的背景颜色 UIBezierPath *path = [UIBezierPath bezierPathWithRect:rect]; [self.backColor set]; [path fill]; // 设置进度终止时显示的内容 if (self.stopTitle) { // 设置下载完成后的标题 [self setTitle:self.stopTitle forState:UIControlStateNormal]; return; } if (self.progress <= 0) { return; } // 清除按钮背景图片 [self setBackgroundImage:nil forState:UIControlStateNormal]; // 设置进度值 [self setTitle:[NSString stringWithFormat:@"%.2f%%", self.progress * 100] forState:UIControlStateNormal]; if (self.isRound) { CGPoint center = CGPointMake(rect.size.height * 0.5, rect.size.height * 0.5); CGFloat radius = (rect.size.height - self.lineWidth) * 0.5; CGFloat startA = - M_PI_2; CGFloat endA = startA + self.progress * 2 * M_PI; // 绘制进度条背景 path = [UIBezierPath bezierPathWithArcCenter:center radius:radius startAngle:0 endAngle:2 * M_PI clockwise:YES]; [[[UIColor lightGrayColor] colorWithAlphaComponent:0.5] set]; path.lineWidth = self.lineWidth; [path stroke]; // 绘制进度条 path = [UIBezierPath bezierPathWithArcCenter:center radius:radius startAngle:startA endAngle:endA clockwise:YES]; path.lineWidth = self.lineWidth; path.lineCapStyle = kCGLineCapRound; [self.lineColor set]; [path stroke]; } else { CGFloat w = self.progress * rect.size.width; CGFloat h = rect.size.height; // 绘制进度条背景 path = [UIBezierPath bezierPathWithRect:CGRectMake(0, 0, rect.size.width, rect.size.height)]; [[[UIColor lightGrayColor] colorWithAlphaComponent:0.5] set]; [path fill]; // 绘制进度条 path = [UIBezierPath bezierPathWithRect:CGRectMake(0, 0, w, h)]; [self.lineColor set]; [path fill]; } } /// 设置进度值 - (void)setProgress:(CGFloat)progress { _progress = progress; [self setNeedsDisplay]; } /// 设置进度终止状态标题 - (void)setStopTitle:(NSString *)stopTitle { _stopTitle = stopTitle; [self setNeedsDisplay]; } @end ViewController.m // 创建进度按钮 QProgressButton *progressButton = [QProgressButton q_progressButtonWithFrame:CGRectMake(100, 100, 100, 50) title:@"开始下载" lineWidth:10 lineColor:[UIColor blueColor] textColor:[UIColor redColor] backColor:[UIColor yellowColor] isRound:YES]; // 设置按钮点击事件 [progressButton addTarget:self action:@selector(progressUpdate:) forControlEvents:UIControlEventTouchUpInside]; // 将按钮添加到当前控件显示 [self.view addSubview:progressButton]; // 设置按钮的进度值 self.progressButton.progress = progress; // 设置按钮的进度终止标题,一旦设置了此标题进度条就会停止 self.progressButton.stopTitle = @"下载完成"; 效果

优秀的个人博客,低调大师

iOS - Quartz 2D 手势截屏绘制

1、绘制手势截屏 具体实现代码见 GitHub 源码 QExtension QTouchClipView.h @interface QTouchClipView : UIView /** * 创建手势截屏视图控件,获取截屏结果 * * @param view 截取图片的视图控件 * @param result 手势截屏结果 * * @return 手势截屏视图控件 */ + (instancetype)q_touchClipViewWithView:(UIView *)view clipResult:(void (^)(UIImage * _Nullable image))result; @end QTouchClipView.m @interface QTouchClipView () /// 截取图片的视图控件 @property (nonatomic, strong) UIView *baseView; /// 滑动手势结果 @property (nonatomic, copy) void (^resultBlock)(UIImage * _Nullable); /// 触摸开始结束点 @property (nonatomic, assign) CGPoint startP; @property (nonatomic, assign) CGPoint endP; @end @implementation QTouchClipView /// 创建手势截屏视图控件,获取截屏结果 + (instancetype)q_touchClipViewWithView:(UIView *)baseView clipResult:(void (^)(UIImage * _Nullable image))result { QTouchClipView *clipView = [[self alloc] initWithFrame:baseView.frame]; clipView.baseView = baseView; clipView.resultBlock = result; return clipView; } /// 初始化 - (instancetype)initWithFrame:(CGRect)frame { if (self = [super initWithFrame:frame]) { self.backgroundColor = [[UIColor blackColor] colorWithAlphaComponent:0.5]; } return self; } /// 触摸开始 - (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(nullable UIEvent *)event { // 获取触摸起始点位置 CGPoint startPoint = [touches.anyObject locationInView:self]; self.startP = startPoint; } /// 触摸移动 - (void)touchesMoved:(NSSet<UITouch *> *)touches withEvent:(nullable UIEvent *)event { // 获取触摸点位置 CGPoint touchPoint = [touches.anyObject locationInView:self]; self.endP = touchPoint; // 刷新视图 [self setNeedsDisplay]; } /// 触摸结束 - (void)touchesEnded:(NSSet<UITouch *> *)touches withEvent:(nullable UIEvent *)event { // 截取屏幕图片 UIGraphicsBeginImageContextWithOptions(self.baseView.bounds.size, NO, 0); CGContextRef ctx = UIGraphicsGetCurrentContext(); [self.baseView.layer renderInContext:ctx]; UIImage *image = UIGraphicsGetImageFromCurrentImageContext(); UIGraphicsEndImageContext(); // 切割图片 CGFloat x = self.startP.x; CGFloat y = self.startP.y; CGFloat w = self.endP.x - x; CGFloat h = self.endP.y - y; CGRect cutRect = CGRectMake(x * 2, y * 2, w * 2, h * 2); CGImageRef cgImage = CGImageCreateWithImageInRect(image.CGImage, cutRect); UIImage *newImage = [[UIImage alloc] initWithCGImage:cgImage]; CGImageRelease(cgImage); // 返回截取结果 if (self.resultBlock) { self.resultBlock(newImage); } // 移除截取视图控件 [self removeFromSuperview]; self.startP = CGPointZero; self.endP = CGPointZero; // 刷新视图 [self setNeedsDisplay]; } /// 触摸取消 - (void)touchesCancelled:(NSSet *)touches withEvent:(nullable UIEvent *)event { [self touchesEnded:touches withEvent:event]; } /// 绘制触摸区域 - (void)drawRect:(CGRect)rect { CGFloat x = self.startP.x; CGFloat y = self.startP.y; CGFloat w = self.endP.x - x; CGFloat h = self.endP.y - y; CGRect clipRect = CGRectMake(x, y, w, h); UIBezierPath *path = [UIBezierPath bezierPathWithRect:clipRect]; [[[UIColor whiteColor] colorWithAlphaComponent:0.2] setFill]; [path fill]; } @end ViewController.m // 创建手势截屏视图 QTouchClipView *touchClipView = [QTouchClipView q_touchClipViewWithView:self.imageView clipResult:^(UIImage * _Nullable image) { // 获取处理截屏结果 if (image) { UIImageWriteToSavedPhotosAlbum(image, self, @selector(image:didFinishSavingWithError:contextInfo:), nil); } }]; // 添加手势截屏视图 [self.view addSubview:touchClipView]; 效果

优秀的个人博客,低调大师

iOS开发技巧 - 使用和定制开关控件(UISwitch)

1. 初始化加载到视图界面 (Swift) import UIKit class ViewController: UIViewController { // 1. create a property of type UISwitch var mainSwitch:UISwitch! override func viewDidLoad() { super.viewDidLoad() // 2. create switch mainSwitch = UISwitch(frame: CGRect(x: 100, y: 100, width: 0, height: 0)) view.addSubview(mainSwitch) } } (Objective-C) #import "ViewController.h" @interface ViewController () // 1. create a property of type UISwitch @property (nonatomic, strong) UISwitch *mainSwitch; @end @implementation ViewController - (void)viewDidLoad { [super viewDidLoad]; // 2. create switch self.mainSwitch = [[UISwitch alloc] initWithFrame: CGRectMake(100, 100, 0, 0)]; [self.view addSubview:self.mainSwitch]; } @end 2. 设置开关状态 (Swift) mainSwitch.setOn(true, animated: true) (Objective-C) [self.mainSwitch setOn:YES]; 3. 判断开关状态 (Swift) if mainSwitch.on{ /* Switch is on */ } else { /* Switch is off */ } (Objective-C) if ([self.mainSwitch isOn]){ NSLog(@"The switch is on."); } else { NSLog(@"The switch is off."); } 4. 添加事件监听 (Swift) mainSwitch.addTarget(self, action: "switchIsChanged:", forControlEvents: .ValueChanged) func switchIsChanged(sender: UISwitch) { println("Sender is = \(sender)") if sender.on{ println("The switch is turned on") } else { println("The switch is turned off") } } (Objective-C) [self.mainSwitch addTarget:self action:@selector(switchIsChanged:) forControlEvents:UIControlEventValueChanged]; - (void) switchIsChanged:(UISwitch *)paramSender { NSLog(@"Sender is = %@", paramSender); if ([paramSender isOn]){ NSLog(@"The switch is turned on."); } else { NSLog(@"The switch is turned off."); } } 5. 定制开关UI /* Adjust the off-mode tint color */ mainSwitch.tintColor = UIColor.redColor() /* Adjust the on-mode tint color */ mainSwitch.onTintColor = UIColor.brownColor() /* Also change the knob's tint color */ mainSwitch.thumbTintColor = UIColor.greenColor()

优秀的个人博客,低调大师

iOS 热更新解读(二)—— JSPatch 源码解析

关于 JSPatch 的实现原理,JSPatch 作者本人 bang 已经有一系列文章阐述: JSPatch 实现原理详解 <一> 核心 JSPatch 实现原理详解 <二> 细节 JSPatch 实现原理详解 <三> 扩展 JSPatch 实现原理详解 <四> 新特性 JSPatch 实现原理详解 <五> 优化 这些文章是对 JSPatch 内部实现原理和细节诸如“require实现”、“property实现”、“self/super 关键字”、“nil处理”、“内存问题”等具体设计思路和解决方案的阐述,并没有对 JSPatch 源码进行解读。在未接触源码、不清楚整个热修复流程的情况下去读这几篇文章难免一头雾水,最好的方法是边读源码边对照上述文章,代码中不理解的地方可以去文章中寻找

优秀的个人博客,低调大师

【iOS发展-61】更换plist经过资源,执行iOS一旦数据仍显示在模拟器的外观,如何解决?

(1)案例介绍 ——我们首先导入plist文件做项目,模拟的观看效果。 ——删除plist,更换一个新的plist,CMD+R模拟执行,或者找到该程序界面上显示最后一个数据。 (2)原因 是由于第一次模拟执行时,已经生成了一个“沙盒”。全部资源也都保存在这个沙盒中了(假设在用户手机中。相当于数据已经下载到用户手机里了)。 这个时候,我们虽然替换了。可是沙盒中得数据仍然是上一次的数据。 (3)解决思路:清除上一次留下的数据,然后又一次载入新的数据plist。(建议2步走) ——先在模拟器中删除应用 ——运行清除数据操作 版权声明:本文博客原创文章,博客,未经同意,不得转载。 本文转自mfrbuaa博客园博客,原文链接:http://www.cnblogs.com/mfrbuaa/p/4753199.html,如需转载请自行联系原作者

资源下载

更多资源
优质分享App

优质分享App

近一个月的开发和优化,本站点的第一个app全新上线。该app采用极致压缩,本体才4.36MB。系统里面做了大量数据访问、缓存优化。方便用户在手机上查看文章。后续会推出HarmonyOS的适配版本。

Mario

Mario

马里奥是站在游戏界顶峰的超人气多面角色。马里奥靠吃蘑菇成长,特征是大鼻子、头戴帽子、身穿背带裤,还留着胡子。与他的双胞胎兄弟路易基一起,长年担任任天堂的招牌角色。

Rocky Linux

Rocky Linux

Rocky Linux(中文名:洛基)是由Gregory Kurtzer于2020年12月发起的企业级Linux发行版,作为CentOS稳定版停止维护后与RHEL(Red Hat Enterprise Linux)完全兼容的开源替代方案,由社区拥有并管理,支持x86_64、aarch64等架构。其通过重新编译RHEL源代码提供长期稳定性,采用模块化包装和SELinux安全架构,默认包含GNOME桌面环境及XFS文件系统,支持十年生命周期更新。

Sublime Text

Sublime Text

Sublime Text具有漂亮的用户界面和强大的功能,例如代码缩略图,Python的插件,代码段等。还可自定义键绑定,菜单和工具栏。Sublime Text 的主要功能包括:拼写检查,书签,完整的 Python API , Goto 功能,即时项目切换,多选择,多窗口等等。Sublime Text 是一个跨平台的编辑器,同时支持Windows、Linux、Mac OS X等操作系统。

用户登录
用户注册
修改密码
忘记密码