-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathTestViewController.swift
More file actions
118 lines (92 loc) · 4.68 KB
/
TestViewController.swift
File metadata and controls
118 lines (92 loc) · 4.68 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
//
// TestViewController.swift
// zhixingche
//
// Created by dev on 5/17/16.
// Copyright © 2016 yunzao. All rights reserved.
//
import UIKit
class TestViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
title = "test";
}
init() {
super.init(nibName: "TestViewController", bundle: nil)
}
required init?(coder aDecoder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
}
@IBAction func alert(sender: UIButton) {
var apperanceLabel: UILabel
if #available(iOS 9.0, *) {
apperanceLabel = UILabel.appearanceWhenContainedInInstancesOfClasses([UIAlertController.self])
} else {
apperanceLabel = UILabel.my_appearanceWhenContainedIn(UIAlertController.self)
}
apperanceLabel.appearanceFont = UIFont.boldSystemFontOfSize(14)
let alertController = UIAlertController(title: "选择发布的内容", message: "", preferredStyle: .ActionSheet)
let rect = CGRect(x: -10, y: -5, width: UIScreen.mainScreen().bounds.width, height: 300)
let customView = UIImageView(frame: rect)
customView.image = UIImage(named: "Community_action_sheet_background_image")
customView.contentMode = .ScaleToFill
alertController.view.addSubview(customView)
alertController.view.sendSubviewToBack(customView)
let color = UIColor(red: 59 / 255.0, green: 80 / 255.0, blue: 105 / 255.0, alpha: 1.0)
let attributes = NSMutableAttributedString(string: "选择发布的内容")
// attributes.addAttribute(NSFontAttributeName, value: UIFont.boldSystemFontOfSize(14), range: NSMakeRange(0, attributes.length))
attributes.addAttributes([NSForegroundColorAttributeName : color], range: NSMakeRange(0, attributes.length))
alertController.setValue(attributes, forKey: "attributedTitle")
let ok = UIAlertAction(title: "拍一张照片", style: .Default, handler: { (action) -> Void in
print("Ok Button Pressed")
})
let picture = UIAlertAction(title: "相册照片", style: .Default, handler: { (action) -> Void in
print("Ok Button Pressed")
})
let cancel = UIAlertAction(title: "取消", style: .Cancel, handler: { (action) -> Void in
print("Cancel Button Pressed")
})
let delete = UIAlertAction(title: "路线", style: .Destructive) { (action) -> Void in
print("Delete Button Pressed")
}
let image = UIImage(named: "action_sheet_creama_image_icon")
ok.setValue(image?.imageWithRenderingMode(.AlwaysOriginal), forKey: "image")
ok.setValue(color, forKey: "titleTextColor")
cancel.setValue(color, forKey: "titleTextColor")
let image2 = UIImage(named: "action_sheet_photo_image_icon")
picture.setValue(image2?.imageWithRenderingMode(.AlwaysOriginal), forKey: "image")
picture.setValue(color, forKey: "titleTextColor")
let image3 = UIImage(named: "action_sheet_line_image_icon")
delete.setValue(image3?.imageWithRenderingMode(.AlwaysOriginal), forKey: "image")
delete.setValue(color, forKey: "titleTextColor")
let viewController = UIViewController()
// viewController.view.backgroundColor = UIColor(white: 1.0, alpha: 0.4)
cancel.setValue(viewController, forKey: "contentViewController")
let alert = UIAlertController(title: "hello", message: "adaa", preferredStyle: .ActionSheet)
alert.addAction(delete)
picture.setValue(alert, forKey: "alertController")
// printLog("action:::\(delete)")
// let height:NSLayoutConstraint =
// NSLayoutConstraint(item: alertController.view,
// attribute: NSLayoutAttribute.Height,
// relatedBy: NSLayoutRelation.Equal,
// toItem: nil,
// attribute: NSLayoutAttribute.NotAnAttribute,
// multiplier: 1,
// constant: 260)
// alertController.view.addConstraint(height);
alertController.addAction(ok)
alertController.addAction(picture)
alertController.addAction(cancel)
alertController.addAction(delete)
presentViewController(alertController, animated: true, completion: nil)
}
}
extension TestViewController {
@IBAction func alertSheet(sender: UIButton) {
print("action")
}
}