隨着公司業務的發展,如今的產品真的是愈來愈 體(sang)貼(xin)用(bing)戶(kuang) 了,恰好前陣子準備作一個後臺可讓用用戶 DIY 本身的小程序,不當心看到了 某網 提供了一套圖標庫,用戶能夠自主選擇,而且能夠進行顏色配置的時候,我就感受事情不妙~css
當時腦子一熱,桌子一拍,咱們也須要提供這樣的功能,並且要作的比他們還強大...html
做爲開發的我默默的留下了這張圖~web
咱們知道小程序裏面是不支持相似 ttf
woff
這類字體的,直接引入編譯都過不去~json
這個就是要告訴咱們,咱們不能像 H5 那樣直接把字體下載下來而後引入到樣式中,這條道路是行不通了,只能從新找找方案了~小程序
嗯,我也不 藏着掖着了 , 接下來給你們 安利 2 中解決方案~後端
方案一bash
利用小程序中不支持 ttf
字體,卻支持 base64
的特色,咱們能夠經過將 ttf
字體轉碼成 base64
,再經過 iconfont
的特色,經過設置字體大小和顏色來達到目的。app
其具體實現以下:xss
iconfont.css
和 iconfont.ttf
這兩個文件,iconfont.ttf
這個文件進行轉碼,將它轉成 base64
格式,恰好 這個網站 就提供了這個功能(pass:這個網站可能會有點慢,能夠的話代理加個速),按照下圖的步驟,分別上傳 ttf
文件,選擇配置,點擊轉換。stylesheet.css
這個文件iconfont.wxss
樣式文件,將 上面解壓出來的 stylesheet.css
裏面的內容所有拷貝到 iconfont.wxss
中,另外,還記得咱們上面說的 iconfont.css
嗎?這時候就要派上用場了,咱們打開 iconfont.css
這個樣式文件,將下面的樣式,也就是我用紅框標註的內容複製到 iconfont.wxss
文件裏,注意上面的不須要複製!!到此爲止,準備工做算是已經完成了,這時候你的 iconfont.wxss
應該相似下面這樣svg
iconfont.wxss
@font-face {
font-family: 'iconfont';
src: url(data:font/truetype;charset=utf-8;base64,AAEAAAANAIAAAwBQRkZUTYR2fJ0AAAm4AAAAHEdERUYAKQANAAAJmAAAAB5PUy8yVuZIqQAAAVgAAABWY21hcLOyB+EAAAHMAAABWmdhc3D//wADAAAJkAAAAAhnbHlmRcqmoQAAAzgAAAOQaGVhZBHw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OC00LDgAAAAASAN4AAQAAAAAAAAAVACwAAQAAAAAAAQAIAFQAAQAAAAAAAgAHAG0AAQAAAAAAAwAIAIcAAQAAAAAABAAIAKIAAQAAAAAABQALAMMAAQAAAAAABgAIAOEAAQAAAAAACgArAUIAAQAAAAAACwATAZYAAwABBAkAAAAqAAAAAwABBAkAAQAQAEIAAwABBAkAAgAOAF0AAwABBAkAAwAQAHUAAwABBAkABAAQAJAAAwABBAkABQAWAKsAAwABBAkABgAQAM8AAwABBAkACgBWAOoAAwABBAkACwAmAW4ACgBDAHIAZQBhAHQAZQBkACAAYgB5ACAAaQBjAG8AbgBmAG8AbgB0AAoAAApDcmVhdGVkIGJ5IGljb25mb250CgAAaQBjAG8AbgBmAG8AbgB0AABpY29uZm9udAAAUgBlAGcAdQBsAGEAcgAAUmVndWxhcgAAaQBjAG8AbgBmAG8AbgB0AABpY29uZm9udAAAaQBjAG8AbgBmAG8AbgB0AABpY29uZm9udAAAVgBlAHIAcwBpAG8AbgAgADEALgAwAABWZXJzaW9uIDEuMAAAaQBjAG8AbgBmAG8AbgB0AABpY29uZm9udAAARwBlAG4AZQByAGEAdABlAGQAIABiAHkAIABzAHYAZwAyAHQAdABmACAAZgByAG8AbQAgAEYAbwBuAHQAZQBsAGwAbwAgAHAAcgBvAGoAZQBjAHQALgAAR2VuZXJhdGVkIGJ5IHN2ZzJ0dGYgZnJvbSBGb250ZWxsbyBwcm9qZWN0LgAAaAB0AHQAcAA6AC8ALwBmAG8AbgB0AGUAbABsAG8ALgBjAG8AbQAAaHR0cDovL2ZvbnRlbGxvLmNvbQAAAgAAAAAAAAAKAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAHAAAAAQACAFsBAgEDAQQDbWFwB3N1Y2Nlc3MDYXRtAAAAAf//AAIAAQAAAAwAAAAWAAAAAgABAAMABgABAAQAAAACAAAAAAAAAAEAAAAA1aQnCAAAAADXaSrKAAAAANdpKso=) format('truetype');
font-weight: normal;
font-style: normal;
}
.iconfont {
font-family:"iconfont" !important;
font-size:16px;
font-style:normal;
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
}
.icon-map:before { content: "\e6a2"; }
.icon-success:before { content: "\e6b3"; }
.icon-atm:before { content: "\e6bd"; }
複製代碼
6.接着,將咱們的字體文件引入到 app.wxss
全局 , 這樣你就能夠在任何你想用到的地方進行調用了,只須要將 class
寫對就沒什麼問題了,
<!--index.wxml-->
<view class="container">
<view class='block'>
<text class='iconfont icon-map'></text>
<text>地圖</text>
</view>
<view class='block'>
<text class='iconfont icon-success'></text>
<text>成功</text>
</view>
<view class='block'>
<text class='iconfont icon-atm'></text>
<text>atm</text>
</view>
</view>
複製代碼
怎麼樣,成功了吧!
什麼? 你要換顏色,難不倒個人,只要改變對應的 color
就能夠了~
<!--index.wxml-->
<view class="container">
<view class='block'>
<text class='iconfont icon-map' style='color : red'></text>
<text>地圖</text>
</view>
<view class='block'>
<text class='iconfont icon-success' style='color : green'></text>
<text>成功</text>
</view>
<view class='block'>
<text class='iconfont icon-atm' style='color : blue'></text>
<text>atm</text>
</view>
</view>
複製代碼
嗯,是否是能夠插會兒腰了~
且慢,剛不是說兩種方案麼,怎麼到這裏就叉起腰來了,還沒完呢,等會嘚瑟哈!!
方案二
剛介紹了方案一,確實是一種選擇,咱們只需約定好樣式,類名,後端將顏色什麼的返回給咱們就行了~
可是這種方案存在弊端,不夠靈活,若是咱們要更新咱們的圖標庫,那麼咱們上面的流程又得走一遍,若是後面圖標庫的類型變多,那麼咱們轉碼後的文件會隨之變大,這對於小程序來講是致命的,由於作小程序都知道,咱們都在時刻想着如何用最少的代碼發揮最大的價值!
因此,這種方案有必定的侷限性,所以纔出了第二套方案~
第二套方案的思路是藉助 svg
矢量圖具備不失真和能夠自主填充顏色的特色,經過 fill
屬性,用戶能夠自定義填充顏色,可是小程序裏面不支持 svg
標籤的,咱們經過顏色選擇器將用戶選擇好的顏色填充到 svg
裏,在經過轉碼將換過顏色的 svg
轉成 base64
編碼發給小程序,小程序能夠直接用在 image
標籤中的 src
屬性上~
咱們一塊兒來試試~
svg
~svg
源代碼直接放在咱們的圖標庫裏面,選擇某個圖標以後,經過顏色選擇器咱們能夠經過 js
設置對應的 svg
圖標的 fill
屬性,動態的給圖標填充不一樣的顏色,差很少就跟下面的效果有點類似~svg
經過 svg
轉 base64
的插件將其轉換成 base64
編碼,這裏爲了方便,我直接偷懶,在線轉換了,對應的 base64
編碼以下:<!--map-->
data:image/svg+xml;base64,PD94bWwgdmVyc2lvbj0iMS4wIiBzdGFuZGFsb25lPSJubyI/PjwhRE9DVFlQRSBzdmcgUFVCTElDICItLy9XM0MvL0RURCBTVkcgMS4xLy9FTiIgImh0dHA6Ly93d3cudzMub3JnL0dyYXBoaWNzL1NWRy8xLjEvRFREL3N2ZzExLmR0ZCI+PHN2ZyBjbGFzcz0iaWNvbiIgd2lkdGg9IjMycHgiIGhlaWdodD0iMzIuMDBweCIgdmlld0JveD0iMCAwIDEwMjQgMTAyNCIgdmVyc2lvbj0iMS4xIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPjxwYXRoIGZpbGw9InJlZCIgZD0iTTUxMy41Nzc4MDcgMTAxOC40ODg0MjVhMjQuNTcyMjI0IDI0LjU3MjIyNCAwIDAgMS0yMC4xOTMwNjYtMTAuNTY4NTQ0TDE5Mi4wMDIwNDggNTczLjM1NDI4YTI0LjY4MDc1NiAyNC42ODA3NTYgMCAwIDEtMC45Mzc4NzktMS40NTgwMTIgMzczLjg4MTk2NSAzNzMuODgxOTY1IDAgMCAxLTM0LjA3Njk1Mi03NS4zNjYxNTFjLTEyLjA3Nzc1MS0zNy4zMTE0MDUtMTguMTk4NTM4LTc2LjE5NjUyMi0xOC4xOTg1MzctMTE1LjU4OTQ4NiAwLTIwNi42NjQwODYgMTY4LjEzMzIzMy0zNzQuNzk4MzQzIDM3NC43OTgzNDItMzc0Ljc5ODM0MyA0Ny45NDM0MyAwIDk2LjAzODM5NiAxMS41NzkxMTkg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U0Ni4zMDAxNThjLTE0LjEzNzgwOSAwLTI1LjU5NzEzMy0xMS40NTkzMjUtMjUuNTk3MTMzLTI1LjU5NzEzM2wwLTc2LjczNzEzM2MwLTE0LjEzNjc4NSAxMS40NTkzMjUtMjUuNTk3MTMzIDI1LjU5NzEzMy0yNS41OTcxMzNzMjUuNTk3MTMzIDExLjQ2MDM0OCAyNS41OTcxMzMgMjUuNTk3MTMzbDAgNzYuNzM3MTMzQzU2MS44OTU5OCA1MzQuODQwODM0IDU1MC40MzU2MzEgNTQ2LjMwMDE1OCA1MzYuMjk4ODQ3IDU0Ni4zMDAxNTh6TTcyMy42Njk4NjEgNTQ2LjMwMDE1OGMtMTQuMTM3ODA5IDAtMjUuNTk3MTMzLTExLjQ1OTMyNS0yNS41OTcxMzMtMjUuNTk3MTMzbDAtNzYuNzM3MTMzYzAtMTQuMTM2Nzg1IDExLjQ1OTMyNS0yNS41OTcxMzMgMjUuNTk3MTMzLTI1LjU5NzEzM3MyNS41OTcxMzMgMTEuNDYwMzQ4IDI1LjU5NzEzMyAyNS41OTcxMzNsMCA3Ni43MzcxMzNDNzQ5LjI2Njk5NCA1MzQuODQwODM0IDczNy44MDY2NDYgNTQ2LjMwMDE1OCA3MjMuNjY5ODYxIDU0Ni4zMDAxNTh6IiAvPjwvc3ZnPg==
複製代碼
base64
編碼發給小程序端,小程序直接放在 image
組件中的 src
屬性便可,對於樣式來講,能夠直接修改 image
的樣式來控制 icon
樣式,效果以下:ok~ 還算是比較圓滿的完成了任務~
這下產品總不會刁難我了吧~
到此,咱們已經 get
到了兩種小程序中實現 icon
自定義顏色的解決方案,對比發現,第一種方案的特色是實現起來比較簡單,步驟什麼的也都還ok,就是拓展性不強,每次改動都須要從新再來一遍,並且對於比較多的圖標來講小程序空間佔用較大,有必定的侷限性,而第二種方案相比於第一種來講雖然在實現過程當中稍微繁瑣了一些,可是帶來的效果是顯而易見的,解決了第一種方案的弊端,拓展性什麼的都很好,是我比較推薦的,也是咱們正在採用的一種方案~
固然,這不過是個人一種實現思路,若是你有關於這方面更好的解決方案記得及時艾特我,我已經火燒眉毛的等待學習了~