您的位置:首页 > 运维架构

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.
}
*/

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: