PopoverController for iPhone
2015-06-21 11:13
543 查看
There is no build-in popup windows or popover controllers for iPhones. Only iPad can use popover controller class.
So i use a third-party controller called FPPopover from github. https://github.com/50pixels/FPPopover
But it is not well-developed. There is a bug in FPPopoverView.m, which leads to the blue label when the arrow is at Up direction and the tint is set to white. It should be:
else
if(self.tint ==FPPopoverWhiteTint)
{
colors[0] = colors[1] = colors[2] =1.0;
colors[4] = colors[5] = colors[6] =1.0;
colors[3] = colors[7] =1.0;
}
And there are no properties for arrow height, rounded radius. Users need to modify them in FPPopoverView.m if they don't want rounded rect.
How to combine OC and Swift?
Create a popover-Bridging-Header.h file
#Import "FPPopoverController.h" of the third-party framework
Add the relative path of popover-Bridging-Header.h, which is: popover/popover-Bridging-Header.h
Then you can use it with Swift
How to use it?
Add files (mentioned in the website), then add delegate to your VC
var popoverView: FPPopoverController?
var contentVC =
PopupViewController()
popoverView =
FPPopoverController(viewController: contentVC)
popoverView!.contentSize =
CGSizeMake(160,
215)
popoverView!.tint =
FPPopoverWhiteTint
popoverView!.arrowDirection =
FPPopoverNoArrow
popoverView!.border =
false
popoverView!.setShadowsHidden(true)
popoverView!.delegate =
self
popoverView!.presentPopoverFromPoint(CGPoint(x: 0, y: _naviHeight))
func popoverControllerDidDismissPopover(popoverController:
FPPopoverController!) {}
class PopupViewController:
UIViewController,UIPickerViewDataSource,UIPickerViewDelegate {
var mthPicker:
UIPickerView?
var mthPickerDSyear:[Int] = []
var bgWidth =
UIScreen.mainScreen().bounds.size.width
var bgHeight =
UIScreen.mainScreen().bounds.size.height
override
func viewDidLoad() {
super.viewDidLoad()
for i
in 0...99 {
mthPickerDSyear.append(selectedYear! -
99 + i)
}
mthPicker =
UIPickerView(frame: CGRect(x:
0, y: -20, width:
150, height: bgHeight))
mthPicker!.dataSource =
self
mthPicker!.delegate =
self
mthPicker?.backgroundColor =
UIColor.whiteColor()
mthPicker!.selectRow(mthPickerDSyear.count
- 1, inComponent: 0, animated:
false)
mthPicker!.selectRow(selectedMonth! -
1, inComponent: 1, animated:
false)
self.view.addSubview(mthPicker!)
}
//UIPickerView
func numberOfComponentsInPickerView(pickerView:
UIPickerView) -> Int {
return
2
}
func pickerView(pickerView:
UIPickerView, numberOfRowsInComponent component:
Int) -> Int {
if (component ==
0){
return
mthPickerDSyear.count
}else{
return
12
}
}
func pickerView(pickerView:
UIPickerView, titleForRow row:
Int, forComponent component: Int) ->
String! {
if (component ==
0){
return
"\(mthPickerDSyear[row])"
}else{
return
"\(row +
1)"
}
}
func pickerView(pickerView:
UIPickerView, didSelectRow row:
Int, inComponent component: Int) {
if (component ==
0){
selectedYear =
mthPickerDSyear[row]
}else{
selectedMonth = row +
1
}
}
override
func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
/*
// MARK: - Navigation
// In a storyboard-based application, you will often want to do a little preparation before navigation
override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
// Get the new view controller using segue.destinationViewController.
// Pass the selected object to the new view controller.
}
*/
}
So i use a third-party controller called FPPopover from github. https://github.com/50pixels/FPPopover
But it is not well-developed. There is a bug in FPPopoverView.m, which leads to the blue label when the arrow is at Up direction and the tint is set to white. It should be:
else
if(self.tint ==FPPopoverWhiteTint)
{
colors[0] = colors[1] = colors[2] =1.0;
colors[4] = colors[5] = colors[6] =1.0;
colors[3] = colors[7] =1.0;
}
And there are no properties for arrow height, rounded radius. Users need to modify them in FPPopoverView.m if they don't want rounded rect.
How to combine OC and Swift?
Create a popover-Bridging-Header.h file
#Import "FPPopoverController.h" of the third-party framework
Add the relative path of popover-Bridging-Header.h, which is: popover/popover-Bridging-Header.h
Then you can use it with Swift
How to use it?
Add files (mentioned in the website), then add delegate to your VC
var popoverView: FPPopoverController?
var contentVC =
PopupViewController()
popoverView =
FPPopoverController(viewController: contentVC)
popoverView!.contentSize =
CGSizeMake(160,
215)
popoverView!.tint =
FPPopoverWhiteTint
popoverView!.arrowDirection =
FPPopoverNoArrow
popoverView!.border =
false
popoverView!.setShadowsHidden(true)
popoverView!.delegate =
self
popoverView!.presentPopoverFromPoint(CGPoint(x: 0, y: _naviHeight))
func popoverControllerDidDismissPopover(popoverController:
FPPopoverController!) {}
class PopupViewController:
UIViewController,UIPickerViewDataSource,UIPickerViewDelegate {
var mthPicker:
UIPickerView?
var mthPickerDSyear:[Int] = []
var bgWidth =
UIScreen.mainScreen().bounds.size.width
var bgHeight =
UIScreen.mainScreen().bounds.size.height
override
func viewDidLoad() {
super.viewDidLoad()
for i
in 0...99 {
mthPickerDSyear.append(selectedYear! -
99 + i)
}
mthPicker =
UIPickerView(frame: CGRect(x:
0, y: -20, width:
150, height: bgHeight))
mthPicker!.dataSource =
self
mthPicker!.delegate =
self
mthPicker?.backgroundColor =
UIColor.whiteColor()
mthPicker!.selectRow(mthPickerDSyear.count
- 1, inComponent: 0, animated:
false)
mthPicker!.selectRow(selectedMonth! -
1, inComponent: 1, animated:
false)
self.view.addSubview(mthPicker!)
}
//UIPickerView
func numberOfComponentsInPickerView(pickerView:
UIPickerView) -> Int {
return
2
}
func pickerView(pickerView:
UIPickerView, numberOfRowsInComponent component:
Int) -> Int {
if (component ==
0){
return
mthPickerDSyear.count
}else{
return
12
}
}
func pickerView(pickerView:
UIPickerView, titleForRow row:
Int, forComponent component: Int) ->
String! {
if (component ==
0){
return
"\(mthPickerDSyear[row])"
}else{
return
"\(row +
1)"
}
}
func pickerView(pickerView:
UIPickerView, didSelectRow row:
Int, inComponent component: Int) {
if (component ==
0){
selectedYear =
mthPickerDSyear[row]
}else{
selectedMonth = row +
1
}
}
override
func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
/*
// MARK: - Navigation
// In a storyboard-based application, you will often want to do a little preparation before navigation
override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
// Get the new view controller using segue.destinationViewController.
// Pass the selected object to the new view controller.
}
*/
}
相关文章推荐
- linux samba
- Hadoop学习(8)----MapReduce讲解
- 开始在linux下做c语言开发
- 系统运维篇之HP-DL580-Linux配置Bonding网卡组实例
- Linux常用命令—文件管理(三)
- 系统运维篇之DellR720-配置Broadcom网卡组配置实例
- Linux使用jstat命令查看jvm的GC情况
- 基于高性能的硬件配置Nginx
- Linux用户操作(在实验楼的学习记录)
- 可穿戴设备领域的两大独角兽FitBit和GoPro数据大PK
- Linux文件权限详解(二)
- linux 服务器配置 matconvnet
- Nginx安装部署
- Apache引起的wampserver安装好第二次使用无法启动问题
- JVM原理、架构—类加载器
- Linux编程实现守护进程
- linux zip解压乱码问题
- telnet远程登录Linux服务器
- LINUX环境下SVN安装与配置(利用钩子同步开发环境与测试环境)
- 换主页轮播的主题图片(2、添加)---轻开电子商务系统(企业入门级B2C网站)