是的,您可以使用Core Graphics创建图标.请按照这些简单的4个步骤绘制3条按钮图标.
2)创建基类UIButton的Cocoa类,将其命名为'NavButton'并粘贴以下代码

import UIKit
class NavButton: UIButton {
override func drawRect(rect: CGRect) {
// thickness of your line
let lineThick:CGFloat = 1.0
// length of your line relative to your button
let lineLenght:CGFloat = min(bounds.width, bounds.height) * 0.8
// color of your line
let lineColor: UIColor = UIColor.whiteColor()
// this will add small padding from button border to your first line and other lines
let marginGap: CGFloat = 5.0
// we need three line
for line in 0...2 {
// create path
let linePath = UIBezierPath()
linePath.lineWidth = lineThick
//start point of line
linePath.moveToPoint(CGPoint(
x: bounds.width/2 - lineLenght/2,
y: 6.0 * CGFloat(line) + marginGap
))
//end point of line
linePath.addLineToPoint(CGPoint(
x: bounds.width/2 + lineLenght/2,
y: 6.0 * CGFloat(line) + marginGap
))
//set line color
lineColor.setStroke()
//draw the line
linePath.stroke()
}
}
}
Run Code Online (Sandbox Code Playgroud)
3)通过Identity Inspector> Custom Class> Class字段NavButton为您UIButton提供课程

4)从"属性检查器">"默认标题"(第四个)中删除按钮的默认标题

| 归档时间: |
|
| 查看次数: |
2956 次 |
| 最近记录: |