Last active
July 12, 2018 08:32
-
-
Save rmzaki/ca3da84472e3ee6908781b2fb35e9444 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import UIKit | |
/** | |
カスタムCellクラス | |
*/ | |
class CustomCell: UITableViewCell { | |
@IBOutlet weak var label: UILabel! | |
override func awakeFromNib() { | |
super.awakeFromNib() | |
// Initialization code | |
} | |
/** | |
drawRectをoverrideしてseparatorを破線にする | |
*/ | |
override func drawRect(rect: CGRect) { | |
let context = UIGraphicsGetCurrentContext(); | |
CGContextSaveGState(context); | |
// 破線の幅設定用 | |
let dashStyle: [CGFloat] = [0.5, 4] //配列でパターンを指定可能 | |
// 先の太さ | |
CGContextSetLineWidth(context, 2.0) | |
// 線の色 | |
CGContextSetStrokeColorWithColor(context, UIColor.blackColor().CGColor) | |
// 破線の幅指定 | |
CGContextSetLineDash(context, 0.0, dashStyle, dashStyle.count) | |
CGContextSetLineCap(context, .Round) | |
CGContextMoveToPoint(context, rect.origin.x, rect.size.height) | |
CGContextAddLineToPoint(context, rect.size.width, rect.size.height) | |
CGContextStrokePath(context) | |
CGContextRestoreGState(context) | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import UIKit | |
/** | |
ViewController | |
*/ | |
class ViewController: UIViewController { | |
// ラベルに表示するデータ | |
let labelTexts: [String] = ["えび味噌ラーメン", "豚骨ラーメン", "塩ラーメン", "味噌ラーメン", "醤油ラーメン"] | |
override func viewDidLoad() { | |
super.viewDidLoad() | |
// Do any additional setup after loading the view, typically from a nib. | |
} | |
override func didReceiveMemoryWarning() { | |
super.didReceiveMemoryWarning() | |
// Dispose of any resources that can be recreated. | |
} | |
} | |
/** | |
テーブルの設定 | |
*/ | |
extension ViewController: UITableViewDataSource { | |
// セクション数 | |
func numberOfSectionsInTableView(tableView: UITableView) -> Int { | |
return 1 | |
} | |
// セクションの行数 | |
func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int { | |
return self.labelTexts.count | |
} | |
// セルの設定 | |
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath:NSIndexPath) -> UITableViewCell { | |
let cell = tableView.dequeueReusableCellWithIdentifier("CustomCell", forIndexPath: indexPath) as! CustomCell | |
cell.label.text = self.labelTexts[indexPath.row] | |
return cell | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment