首页
学习
活动
专区
工具
TVP
发布
精选内容/技术社群/优惠产品,尽在小程序
立即前往

UIView内部没有出现UIGraphicsGetCurrentContext

UIView是iOS开发中的一个基础视图类,用于构建用户界面。UIGraphicsGetCurrentContext是一个函数,用于获取当前图形上下文。在UIView内部没有出现UIGraphicsGetCurrentContext的情况下,可能有以下几种可能性:

  1. UIView并不涉及绘制操作:UIView主要负责用户界面的布局和交互,不涉及具体的绘制操作。因此,在一些简单的界面中,可能不会出现获取图形上下文的需求。
  2. 绘制操作在其他地方进行:有时候,绘制操作可能会在其他地方进行,比如在自定义的继承自UIView的子类中重写drawRect方法,或者在CALayer的绘制方法中进行。这些地方会直接获取图形上下文进行绘制操作,而不是在UIView内部获取。
  3. 使用高级绘图框架:在一些复杂的绘制场景中,可能会使用更高级的绘图框架,如Core Graphics或Metal。这些框架提供了更强大的绘制功能,并且可以直接操作图形上下文,而不需要通过UIGraphicsGetCurrentContext函数来获取。

总之,UIView内部没有出现UIGraphicsGetCurrentContext可能是因为UIView本身的职责不涉及具体的绘制操作,或者绘制操作在其他地方进行,或者使用了其他高级的绘图框架。如果需要在UIView内部进行绘制操作,可以通过重写drawRect方法或者使用其他绘图框架来实现。

页面内容是否对你有帮助?
有帮助
没帮助

相关·内容

  • IOS 图文新闻文章样式

    //在实现图文混排的功能之前,首先往项目中添加一个继承自UIView 父类的子类CTImageView.swift。使用该类的draw方法,并在该方法中使 用Core Text框架渲染富文本, 1 let picWidth = CGFloat(200.0) 2 let picHeight = CGFloat(133.0) 3 UIColor.brown.setFill() 4 UIRectFill(rect) 5 var ctRunCallback = CTRunDelegateCallbacks(version: kCTRunDelegateVersion1, dealloc: { (refCon) -> Void in 6 }, getAscent:{ ( refCon) -> CGFloat in 7 return picHeight 8 }, getDescent:{ (refCon) -> CGFloat in 9 return 0 10 }) { (refCon) -> CGFloat in 11 return picWidth 12 } 13 var picture = “coffee “ 14 let ctRunDelegate = CTRunDelegateCreate(&ctRunCallback, &picture) 15 let placeHolder = NSMutableAttributedString(string:” “) 16 placeHolder.addAttribute(kCTRunDelegateAttributeName as String, value:ctRunDelegate!, range: NSMakeRange(0, 1)) 17 placeHolder.addAttribute(“pictureName”, value: picture, range:NSMakeRange(0, 1)) 18 let article = “咖啡(coffee)是采用经过烘焙的咖啡豆所 制作出来\n\n的饮料,通常为热饮,但也有 作为冷饮的冰咖啡。 咖啡是人类社会流行范围最为广泛的饮料之一,也是重要经济作 物。在繁忙的工作生活 之余,我们可以去尝试做自己的咖啡。” 19 let attributedStr = NSMutableAttributedString(string: article) 20 attributedStr.insert(placeHolder, at:27) 21 attributedStr.addAttribute(kCTUnderlineStyleAttributeName as String, value:NSNumber(value:1), range: NSRange(location:0, length:attributedStr.length)) 22 let framesetter = CTFramesetterCreateWithAttributedString(attributedStr) 23 let path = UIBezierPath(rect:rect) 24 let ctFrame = CTFramesetterCreateFrame(framesetter, CFRangeMake(0, attributedStr.length), path.cgPath, nil) 25 26 let crtContext = UIGraphicsGetCurrentContext() 27 crtContext!.textMatrix = CGAffineTransform.identity 28 crtContext?.scaleBy(x:1.0, y:-1.0) 29 crtContext?.translateBy(x:0, y: self.bounds.size.height * -1) 30 CTFrameDraw(ctFrame, crtContext!) 31 let ctLines = CTFrameGetLines(ctFrame) as NSArray 32 var originsOfLines = CGPoint 33 for _ in 0..<ctLines.count{ 34 originsOfLines.append(CGPoint.zero) 35 } 36 let range:CFRange = CFRangeMake(0, 0) 37 CTFrameGetLineOrigins(ctFrame, range, &originsOfLines) 38 for i in 0..<ctLines.co

    02
    领券