1. 程式人生 > >iOS 鏤空文字效果

iOS 鏤空文字效果

#import "HollowOutLabel.h"

@implementation HollowOutLabel

{

NSString * _text;

UIFont * _font;

UIColor * _backgroundColor;

CGRect _frame;

}

#pragma mark - 重寫對應的set方法

- (void)setText:(NSString *)text

{

_text = text;

}

- (void)setFont:(UIFont *)font

{

_font = font;

}

- (void)setBackgroundColor:(

UIColor *)backgroundColor

{

_backgroundColor = backgroundColor;

}

//這個方法會出問題,因而重寫置空

- (void)sizeToFit

{

}

- (instancetype)init//禁止使用此方法初始化

{

returnnil;

}

- (instancetype)initWithFrame:(CGRect)frame

{

if (self = [superinitWithFrame:frame]) {

_frame = frame;

    }

returnself;

}

#pragma mark -

繪製

- (void)drawRect:(CGRect)rect

{

CGContextRef context = UIGraphicsGetCurrentContext();

    [selfdrawSubtractedText:_textinRect:_frameinContext:context];

}

- (void)drawSubtractedText:(NSString *)text inRect:(CGRect)rect inContext:(CGContextRef)context

{

//將當前圖形狀態推入堆疊

CGContextSaveGState(context);

//設定混合色

CGContextSetBlendMode(context, kCGBlendModeDestinationOut);

//label上面新增label

UILabel *label = [[UILabelalloc] initWithFrame:rect];

    label.font = _font;

    label.text = text;

    label.textAlignment = NSTextAlignmentCenter;

    label.backgroundColor = _backgroundColor;

    [label.layerdrawInContext:context];

//把堆疊頂部的狀態彈出,返回到之前的圖形狀態

CGContextRestoreGState(context);

}

@end


相關推薦

iOS 鏤空文字效果

#import "HollowOutLabel.h" @implementation HollowOutLabel { NSString * _text; UIFont * _font; UIColor * _backgroundColor; CGRect _frame; } #pra

iOS 漸變文字效果

func setGradientText() -> Void { titlDb = createLabel(rect: CGRect.init(x: 0, y: 0, width: 100, height: 100), text: "這是一個lab

iOS 漸變色 以及 鏤空效果的實現(Mask的妙用)以及鏤空文字的實現

實現起來也很簡單,主要分3個步驟: 1.建立一個鏤空的路徑:   UIBezierPath 有個原生的方法- (void)appendPath:(UIBezierPath *)bezierPath, 這個方法作用是倆個路徑有疊加的部分則會鏤空.   這個方法實現原理

仿ios的滑動效果

public 頭部 ati 設置 class iss generated ttr stat package code.suibianchou.com.custormview2;import android.annotation.SuppressLint;import and

iOS分組通訊錄效果+側滑菜單(MMDrawerController)

ntc 函數 處理方法 cocoa javascrip enter title clas uiwindow 前言的廢話…能夠忽略 自從學會了使用Cocoapod,就欲罷不能了!由於太簡單太贊了,不用再把源代碼粘到project裏了! 參見戴維營博客中

vue 實現 ios 原生picker 效果(實現思路分析)

sta 效果 cursor touchend orm dex tex sub alt 以前最早實現了一個類似的時間選擇插件,但是適用範圍太窄,索性最近要把這個實現方式發布出來,就重寫了一個高復用的vue組件。 支持安卓4.0以上,safari 7以上 效果預覽 gitHu

iOS文字符判斷 正則NSRegularExpression 謂詞NSPredicate 和 NSRange

直接 matching ring mat arch 查找 alua str ogr 廢話不說,直接上代碼 #pragma mark - 中文字符判斷 - (BOOL)validateContainsChinese:(NSString *)content { NS

使用SVG + CSS實現動態霓虹燈文字效果

rdp orm ans cnblogs fill href 大神 case ima 效果圖: 原理:多個SVG描邊動畫使用不同的animation-delay即可! 對於一個形狀SVG元素或文本SVG元素,可以使用stroke-dasharray來控制描邊的間隔樣式,並且

iOS UILable 文字添加圖片 (文字前面,中間,後面添加圖)

str nbsp tab 添加 tac nsa end agen mut 1,實例化一個UILable 2, // 創建一個富文本 NSMutableAttributedString *attri = [[NSMutableAttributedString

第95天:CSS3 邊框、背景和文字效果

決定 shadow css3多列 應該 bre column set 動畫 css3   1、CSS3邊框: border-radius:CSS3圓角邊框。在 CSS2 中添加圓角矩形需要技巧,我們必須為每個圓角使用不同的圖片,在 CSS3 中,創建圓角是非常容易的,在

iType.js仿輸入文字效果

htm github pan loop ont 輸入 lan ron html <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> &

marquee標簽屬性詳解(跑馬燈文字效果

del mouseover 鼠標 AR 百分數 lte 距離 BE 100% <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DT

[UGUI]Text文字效果

.get 參考 添加 set col gradient 內容 .cn osi 參考鏈接: http://www.xuanyusong.com/archives/3471 https://www.cnblogs.com/lyh916/p/9162463.html 0.Te

ios原生文字轉語音

link inf oid uic 是我 代理方法 聲音錄制 初始 https 因新項目需求,需要接入類似支付寶收款提示聲----“支付寶到賬xxxx元”,就查看了一些文章,蘋果還是想的很周全,廢話不多說。 首先 在General -> Linked Framewor

Atiitt 圖片影象驗證碼生成法原理 目錄 1.1. 常見的最簡單圖片驗證碼是利用影象api把隨機數文字轉影象 1 1.2. 常見較為複雜圖片驗證碼的方法 ( 鏤空文字 打散 干擾線 文字扭曲

Atiitt 圖片影象驗證碼生成法原理   目錄 1.1. 常見的最簡單圖片驗證碼是利用影象api把隨機數文字轉影象 1 1.2. 常見較為複雜圖片驗證碼的方法 ( 鏤空文字  打散 干擾線 文字扭曲 粘連  膨脹,填充 ) 1 1.3. 實現 2

ios文字的高度

+ (CGFloat)getStrHeightWithAttributeStr:(NSAttributedString *)string viewWidth:(CGFloat)viewWidth{ if (string.

ios UIButton 文字透明度設定

[self.navBar.rightButton2 setTitleColor:TFCOLOR_0093FF forState:UIControlStateNormal]; [self.navBar.rightButton2 setTitleColor:[UIColor colorWithR

精通CSS+DIV網頁樣式與佈局 CSS文字效果

分享一下我老師大神的人工智慧教程!零基礎,通俗易懂!http://blog.csdn.net/jiangjunshow 也歡迎大家轉載本篇文章。分享知識,造福人民,實現我們中華民族偉大復興!        

iOS UILabel文字新增描邊實現

可以達到文字描一圈黑邊的效果: 繼承UILabel以後過載drawTextInRect: - (void)drawTextInRect:(CGRect)rect { CGSize shad

CSS3文字效果

文字陰影text-shadow:指定了水平陰影,垂直陰影,模糊的距離,以及陰影的顏色: 例:text-shadow: 5px 5px 5px #FF0000; 盒子陰影box-shadow 陰影的一個使用特例是卡片效果:文字卡片、圖片卡片 顯示溢位內容:text-overflo