March.5th

CGGeometry.h ( 幾何類 )
一 幾個常用結(jié)構(gòu)體

struct CGPoint {

CGFloat x;

CGFloat y;

}; 定義一個點,設(shè)置x坐標和y坐標

struct CGSize {

CGFloat width;

CGFloat height;

}; 定義一個尺寸,設(shè)置寬度和高度

struct CGVector {

CGFloat dx;

CGFloat dy;

}; 定義一個二維矢量

struct CGRect {

CGPoint origin;

CGSize size;

}; 定義一個矩形

UIImage

todo

UIBezierPath:http://www.henishuo.com/uibezierpath-draw/
一.畫圖步驟
1.創(chuàng)建一個UIBezierPath對象
2.調(diào)用-moveToPoint:設(shè)置初始線段的起點
3.添加線或者曲線去定義一個或者多個子路徑
4.改變對象跟繪圖相關(guān)的屬性:(畫筆的顏色 樣式等等)

二.創(chuàng)建方法
****+ (****instancetype****)****bezierPath;****
最常用的創(chuàng)建方法,可以畫任意圖形

****+ (****instancetype****)****bezierPathWithRect****:****(****CGRect****)****rect;****
畫一個矩形曲線

****+ (****instancetype****)****bezierPathWithOvalInRect****:****(****CGRect****)****rect;****
通常用來畫圓和橢圓

****+ (****instancetype****)****bezierPathWithRoundedRect****:****(****CGRect****)rect****
**** cornerRadius**:****(****CGFloat****)****cornerRadius****;******
用來畫矩形,可以畫圓角矩形,第一個參數(shù)是矩形大小位置,第二個是圓角大小


****+ (****instancetype****)****bezierPathWithRoundedRect****:****(****CGRect****)rect****
**** byRoundingCorners:****(****UIRectCorner****)****corners******
**** cornerRadii
:****(****CGSize****)****cornerRadii****;******
方法類似上面的,可以指定哪一個角是圓角



****+ (****instancetype****)****bezierPathWithArcCenter****:****(****CGPoint****)center****
**** radius:****(****CGFloat****)****radius******
**** startAngle
:****(****CGFloat****)****startAngle******
**** endAngle:****(****CGFloat****)****endAngle******
**** clockwise
:****(****BOOL****)****clockwise****;******
用來畫圓弧


****+ **(****instancetype****)****bezierPathWithCGPath****:****(****CGPathRef****)****CGPath****;******


三.效果(圖可以參見上面的網(wǎng)址)
1.畫三角形
UIBezierPath *path = [UIBezierPath bezierPath];
//設(shè)置路徑的起點

[path moveToPoint:CGPointMake(20, 20)];
//移動路徑到直線的另一點

[path addLineToPoint:CGPointMake(self.frame.size.width - 40, 20)];
[path addLineToPoint:CGPointMake(self.frame.size.width / 2, self.frame.size.height - 20)];

// 最后的閉合線是可以通過調(diào)用closePath方法來自動生成的,也可以調(diào)用-addLineToPoint:方法來添加
// [path addLineToPoint:CGPointMake(20, 20)];

[path closePath];

// 設(shè)置線寬
path.lineWidth = 1.5;

// 設(shè)置填充顏色
UIColor *fillColor = [UIColor greenColor];
//啟動一下顏色

[fillColor set];
//給路線填充顏色

[path fill];

// 設(shè)置畫筆顏色
UIColor *strokeColor = [UIColor blueColor];
[strokeColor set];

// 根據(jù)我們設(shè)置的各個點連線
[path stroke];

2.畫矩形
1?普通矩形
UIBezierPath *path = [UIBezierPath bezierPathWithRect:
CGRectMake(20, 20, self.frame.size.width - 40, self.frame.size.height - 40)];

2?圓角矩形
UIBezierPath *path = [UIBezierPath bezierPathWithRoundedRect:
CGRectMake(20, 20, self.frame.size.width - 40, self.frame.size.height - 40)
cornerRadius:10];
3?特定角是圓角
UIBezierPath *path = [UIBezierPath bezierPathWithRoundedRect:
CGRectMake(20, 20, self.frame.size.width - 40, self.frame.size.height - 40)
byRoundingCorners:UIRectCornerTopRight cornerRadii:CGSizeMake(20, 20)];

4?畫圓跟橢圓
UIBezierPath *path = [UIBezierPath bezierPathWithOvalInRect:
CGRectMake(20, 20, self.frame.size.width - 40, self.frame.size.width - 40)];
ps:傳入的矩形是一個正方形,那么就會得到一個圓,不是正方形是就是橢圓

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

  • 1.使用UIBezierPath畫圖步驟 創(chuàng)建一個UIBezierPath對象 調(diào)用-moveToPoint:設(shè)置...
    翹楚iOS9閱讀 761評論 1 2
  • Quartz2D以及drawRect的重繪機制字數(shù)1487 閱讀21 評論1 喜歡1一、什么是Quartz2D Q...
    PurpleWind閱讀 907評論 0 3
  • UIBezierPath詳解 我在寫本篇文章之前,也沒有系統(tǒng)學習過貝塞爾曲線,只是曾經(jīng)某一次的需求需要使用到,才臨...
    白水灬煮一切閱讀 1,280評論 0 4
  • 基礎(chǔ)知識 使用UIBezierPath可以創(chuàng)建基于矢量的路徑,此類是Core Graphics框架關(guān)于路徑的封裝。...
    十里桃花不及你閱讀 954評論 0 5
  • 家是什么? 家是什么?是一束溫暖的陽光,可以融化掉心上的冰雪寒霜;是一盞明燈,可以照亮夜行人晚歸的路程;是一個溫馨...
    嗚哩哇啦叭叭叭閱讀 421評論 0 0

友情鏈接更多精彩內(nèi)容