首页
学习
活动
专区
圈层
工具
发布
    • 综合排序
    • 最热优先
    • 最新优先
    时间不限
  • 来自专栏TechBox

    Swift 范的 CGRect、CGSize 和 CGPoint(转)

    CGRect, CGSize, CGPoint C 语法 —— 披着羊皮的狼 我相信下面这种写法,很多 Swift 开发者都会中枪,让我看见你们的双手! 所以,让我们来看看正确的 Swift 姿势吧: let rect = CGRect(x: 0, y: 0, width: 100, height: 100) let size = CGSize(width let rect = CGRect.zero let size = CGSize.zero let point = CGPoint.zero 这样写代码也更为清晰,Xcode 会将 . let frame = CGRect(x: 0, y: 0, width: 100, height: 100) let width = frame.width let height = frame.height 也终于不用为了修改 CGRect 的某一个值,而去创建一个全新的结构体了。

    7.7K30发布于 2018-06-05
  • 来自专栏一“技”之长

    iOS(CGGeometry)几何类方法总结 原

    (CGRect rect); 获取矩形最下端的y值 CGFloat CGRectGetWidth(CGRect rect); 获取矩形宽度 CGFloat CGRectGetHeight(CGRect rect1, CGRect rect2); 判断两个矩形是否相等 CGRect CGRectStandardize(CGRect rect); 根据一个矩形创建一个标准的矩形 bool CGRectIsEmpty (CGRect rect); 判断是否为零矩形 CGRectIsNull(CGRect rect); 判断是否为空矩形 bool CGRectIsInfinite(CGRect rect); 判断是否为无限矩形 CGRect CGRectIntegral(CGRect rect) 根据一个矩形,返回四个参数都是整数的矩形 CGRect CGRectUnion(CGRect r1, CGRect r2); 返回两个矩形的并集 CGRect CGRectIntersection(CGRect r1, CGRect r2); 返回两个矩形的交集,如果没有交集,返回空矩形 CGRect CGRectOffset(CGRect rect

    1.1K20发布于 2018-08-15
  • 来自专栏iOSer成长记录

    iOS-自定义button详解

    (0, 0, 10, 10); // 1 3 5 8 10 12 15 17 19 } // 返回标题边界 -(CGRect)titleRectForContentRect:(CGRect)contentRect 刚开始对这几个函数不是很明白,经过多次调试,才明白各自的功能: -(CGRect)backgroundRectForBounds:(CGRect)bounds 该函数返回的是背景view的大小,参数bounds :(CGRect)bounds确定 -(CGRect)imageRectForContentRect:(CGRect)contentRect 该函数返回图片view的大小,参数contentRect由函数 view都和它的frame一样大,所以可以不用重写-(CGRect)backgroundRectForBounds:(CGRect)bounds和-(CGRect)contentRectForBounds :(CGRect)bounds这两个函数 // 返回标题边界 -(CGRect)titleRectForContentRect:(CGRect)contentRect{ // 这contentRect

    1.1K30发布于 2018-06-29
  • 来自专栏前端文章小tips

    UISlider实现整数滑动,点击响应,大小高度样式定制

    )minimumValueImageRectForBounds:(CGRect)bounds; - (CGRect)maximumValueImageRectForBounds:(CGRect)bounds ; - (CGRect)trackRectForBounds:(CGRect)bounds; - (CGRect)thumbRectForBounds:(CGRect)bounds trackRect: (CGRect)rect value:(float)value; 滑块的大小和轨道的高度需要在子类中重写,我们看到需要返回的是CGRect,value改变的时候轨道大小和滑块位置自然是在变化的,也就是说 )minimumValueImageRectForBounds:(CGRect)bounds; 对应maximumValueImage的大小 (CGRect)maximumValueImageRectForBounds :(CGRect)bounds; (CGRect)thumbRectForBounds:(CGRect)bounds trackRect:(CGRect)rect value:(float)value{

    2.2K20编辑于 2021-12-09
  • 来自专栏ShaoYL

    1.了解Objective-C语言

    比如 CGRect; CGRect frame; frame.origin.x = 0.0f; frame.origin.y = 10.0f; frame.size.width = 100.0f; frame.size.height = 150.0f; // CGRect 是 C 结构体,其定义是: struct CGRect { CGPoint origin; CGSize size; }; type struct CGRect CGRect; 整个系统架构都在使用这种结构体,因为如果改用 对象来做的话,性能会受影响。 与创建结构体相比,创建对象还需要额外开销,例如分配及释放堆内存等,如果只需保存 int、float、double、chat、等“非对象类型”,那么通常使用CGRect这种结构体就可以了。

    70860发布于 2018-06-21
  • 来自专栏ShaoYL

    1.了解Objective-C语言

    比如 CGRect; CGRect frame; frame.origin.x = 0.0f; frame.origin.y = 10.0f; frame.size.width = 100.0f; frame.size.height = 150.0f; // CGRect 是 C 结构体,其定义是: struct CGRect { CGPoint origin; CGSize size; }; type struct CGRect CGRect; 整个系统架构都在使用这种结构体,因为如果改用 对象来做的话,性能会受影响。 与创建结构体相比,创建对象还需要额外开销,例如分配及释放堆内存等,如果只需保存 int、float、double、chat、等“非对象类型”,那么通常使用CGRect这种结构体就可以了。

    854100发布于 2018-05-11
  • 来自专栏学海无涯

    iOS26适配指南之UIVisualEffectView

    ViewController: UIViewController { lazy var wwdcLabel: UILabel = { let label = UILabel(frame: CGRect glassEffect.isInteractive = true visualEffectView.effect = glassEffect visualEffectView.frame = CGRect ViewController: UIViewController { lazy var wwdcLabel: UILabel = { let label = UILabel(frame: CGRect return label }() lazy var iOSLabel: UILabel = { let label = UILabel(frame: CGRect = UIGlassEffect() let view1 = UIVisualEffectView(effect: glassEffect) view1.frame = CGRect

    85510编辑于 2025-08-12
  • 来自专栏sktj

    IOS移动开发从入门到精通 视图UIView、层CALayer(1)

    let view = UIView(frame:CGRect(x:40, y:80,width:240, height:240)) view.backgroundColor = UIColor.black 新建Swift File import UIKit class RoundView:UIView { var color = UIColor.blue override init(frame:CGRect ) { super.init(frame:frame) self.backgroundColor = UIColor.clear } override func draw(_ rect:CGRect fillEllipse(in:CGRect(x:0, y:0, width:self.frame.width, height:self.frame.height)) } required init? let view = RoundView(frame:CGRect(x:40, y:40,width:240, height:240)) self.view.addSubview(view) }

    1.1K30发布于 2019-07-05
  • 来自专栏一“技”之长

    iOS UIButton解读

    @property(nonatomic,readonly,retain) UIImageView *imageView  NS_AVAILABLE_IOS(3_0); 六、下面这些函数,都会返回一个CGRect 矩形范围 - (CGRect)backgroundRectForBounds:(CGRect)bounds; //返回背景大小 - (CGRect)contentRectForBounds:(CGRect )bounds; //返回视图大小,包括标题和图片 - (CGRect)titleRectForContentRect:(CGRect)contentRect; //返回标题大小 - (CGRect)imageRectForContentRect :(CGRect)contentRect; //返回图片大小 关于触发事件,button是继承于UIControl,这里不再叙述。

    89420发布于 2018-08-15
  • 来自专栏一“技”之长

    iOS开发CoreGraphics核心图形框架之二——深入理解图形上下文

    //下面这两个方法用于向当前的图形上下文中填充矩形 UIKIT_EXTERN void UIRectFillUsingBlendMode(CGRect rect, CGBlendMode blendMode (CGRect rect, CGBlendMode blendMode); UIKIT_EXTERN void UIRectFrame(CGRect rect); //这个方法用于裁剪当前的图形上下文的绘制区域 UIKIT_EXTERN void UIRectClip(CGRect rect); 上面方法中的CGBlendMode参数用于设置图像的混合模式,意义列举如下: typedef CF_ENUM (int32 可以设置边框宽度 void CGContextStrokeRectWithWidth(CGContextRef cg_nullable c, CGRect rect, CGFloat width); CGRect CGContextConvertRectToUserSpace(CGContextRef cg_nullable c, CGRect rect); //下面这些方法已经被弃用 //设置字体

    3.2K20发布于 2018-08-15
  • 来自专栏DannyHoo的专栏

    单独设置UIView的坐标x或y或width或height

    代码: CGRect frame = imageV.frame;     frame.origin.x = 0;     imageV.frame= frame; 如果想要像 imageV.frame.origin.x reserved. // #import "UIView+Frame.h" @implementation UIView (Frame) - (void)setX:(CGFloat)x { CGRect self.frame = frame; } - (CGFloat)x { return self.frame.origin.x; } - (void)setY:(CGFloat)y { CGRect self.frame.origin.y; } - (CGFloat)width { return self.frame.size.width; } - (void)setWidth:(CGFloat)width { CGRect } - (CGFloat)height { return self.frame.size.height; } - (void)setHeight:(CGFloat)height { CGRect

    1.8K10发布于 2018-09-13
  • 来自专栏APP自动化测试

    使用UIBezierPath绘制图形

    BezierView继承自UIView并重写drawRect方法 #import "BezierView.h" @implementation BezierView - (void)drawRect:(CGRect 我们可以用UIBezierPath的bezierPathWithRect:CGRect(rect)方法来画矩形, 代码如下 - (void)drawRect:(CGRect)rect { // 我们可以用UIBezierPath的bezierPathWithOvallInRect:CGRect(rect)方法来画圆形和椭圆, 代码如下 - (void)drawRect:(CGRect)rect 用下面这个方法画带指定远角的矩形 + (instancetype)bezierPathWithRoundedRect:(CGRect)rect byRoundingCorners:(UIRectCorner 上代码: - (void)drawRect:(CGRect)rect { // Drawing code //设置线条颜色 UIColor *color = [UIColor

    1.4K40发布于 2019-10-15
  • 来自专栏iOS面试技术问题

    Swift日常开发随笔

    //颜色创建图片 func imageFromColor(color: UIColor, viewSize: CGSize) -> UIImage{ let rect: CGRect = CGRect(x: 0, y: 0, width: viewSize.width, height: viewSize.height) UIGraphicsBeginImageContext var pageControl: NACustomBannerPageControl = { let node = NACustomBannerPageControl(frame: CGRect page resetImageView() startTimer() } // MARK: - Init init(frame: CGRect <totalArry.count{ let tableView = UITableView.init(frame: CGRect.init(x: 0,

    2.3K22发布于 2020-10-11
  • 来自专栏Alice

    ios_UITextField-修改占位文字和光标的颜色,大小

    自定义的UITextField,获取到焦点(编辑状态)的时候是白色,失去焦点(非编辑状态)的时候是灰色: 方法三.将占位文字画上去(重写- (void)drawPlaceholderInRect:(CGRect )rect;) - (void)drawPlaceholderInRect:(CGRect)rect { [[UIColor orangeColor] set]; [self.placeholder systemFontOfSize:20]]; } 二.设置光标颜色 // 设置光标的颜色 self.tintColor = [UIColor redColor]; 三.设置占位文字的偏移 重写-(CGRect )placeholderRectForBounds:(CGRect)bounds;方法 可以用来设置光标与占位的间距 扩充:系统还提供了很多类似的方法 – textRectForBounds:  )placeholderRectForBounds:(CGRect)bounds { //return CGRectInset(bounds, 20, 0); CGRect inset =

    1.5K10发布于 2018-12-26
  • 来自专栏编程之旅

    UITextField设置leftView、圆角以及文字距离

    我们可以子类化一个TextField,去复写它的一个方法来设置leftView的位置 - (CGRect)leftViewRectForBounds:(CGRect)bounds { CGRect //UITextField 文字与输入框的距离 - (CGRect)textRectForBounds:(CGRect)bounds{ return CGRectInset(bounds , 45, 0); } //控制文本的位置 - (CGRect)editingRectForBounds:(CGRect)bounds{ return CGRectInset

    2.6K10发布于 2018-08-30
  • 来自专栏码农的生活

    iOS调整按纽图片文字title位置的代码

    "SuperButton.h" #import "UtilsFunctions.h" @interface SuperButton () { CGRect @end @implementation SuperButton //自定义的初始化方法 - (instancetype)initWithFrame:(CGRect )imageRectForContentRect:(CGRect)contentRect { CGFloat imageX=self.frame.size.width/2 +boundingRect.size.width/2; UIScreen *s=[UIScreen mainScreen]; CGRect rect=s.bounds return CGRectMake(imageX, imageY, width, height); } 2.改变title文字的位置,构造title的矩形即可 - (CGRect

    1.3K00发布于 2021-10-31
  • 来自专栏DannyHoo的专栏

    UILabel显示固定行数的问题

    = [NSMutableDictionary dictionary];     dic[NSFontAttributeName] = [UIFont systemFontOfSize:17]; CGRect attributes:dic context:nil]; NSLog(@"%f-----%f", rect.size.width, rect.size.height);     lbl.frame = (CGRect = [NSMutableDictionary dictionary];     dic[NSFontAttributeName] = [UIFont systemFontOfSize:17]; CGRect attributes:dic context:nil]; NSLog(@"%f-----%f", rect.size.width, rect.size.height);     lbl.frame = (CGRect , rect.size}; if (rect.size.height > 102) {         lbl.numberOfLines = 5;         lbl.frame = (CGRect

    1.7K20发布于 2018-09-13
  • 来自专栏xx_Cc的学习总结专栏

    iOS-UIButton 全面解析UIButton 的全面解析

    property(nullable, nonatomic,readonly,strong) UIImageView *imageView NS_AVAILABLE_IOS(3_0); 指定背景边界 - (CGRect )backgroundRectForBounds:(CGRect)bounds; 指定内容边界 - (CGRect)contentRectForBounds:(CGRect)bounds; 指定标题边界 - (CGRect)titleRectForContentRect:(CGRect)contentRect; 指定图片边界 - (CGRect)imageRectForContentRect:(CGRect )contentRect; 示例: - (CGRect)imageRectForContentRect:(CGRect)bounds{ return CGRectMake(0.0, 0.0

    2.2K80发布于 2018-05-10
  • 来自专栏编程之旅

    iOS开发——定制UITextField

    可是placeholde的默认属性是紧贴文本输入框的,而且字体以及字体大小也不美观,于是我们可以这么来设置placeholder //控制placeHolder的位置,左右缩20 -(CGRect)placeholderRectForBounds :(CGRect)bounds { return CGRectInset(bounds, 20, 4); } //控制左视图位置 - (CGRect)leftViewRectForBounds :(CGRect)bounds { return CGRectInset(bounds,0,0); } //控制编辑文本的位置 -(CGRect)editingRectForBounds:( CGRect)bounds { return CGRectInset( bounds, 20, 0); } //控制显示文本的位置 -(CGRect)textRectForBounds:(CGRect

    2.3K40发布于 2018-08-30
  • 来自专栏TechBox

    UITableViewCell系列之(二)视觉差滚动效果前言

    只能是UIViewController的view上添加一个UITableView ---- 3. demo中涉及到了坐标系转换的问题,不了解坐标系转换的可以参考如下两个方法的使用: // - (CGRect )convertRect:(CGRect)rect toView:(nullable UIView *)view; // 把以A视图为坐标系的rect1转换为以B视图为坐标系的rect2并返回rect2 CGRect rect2 = [A convertRect:rect1 toView:B]; // - (CGRect)convertRect:(CGRect)rect fromView:(nullable UIView *)view; // 把以B视图为坐标系的frame1转换为以B视图为坐标系的frame2并返回frame2 CGRect frame2 = [A convertRect:frame1 distanceWillMove = distanceOfCenterY / CGRectGetHeight(view.frame) * distanceH; // 5.更新图片的Y值 CGRect

    6.5K30发布于 2018-06-05
领券