iPhone:如何在iPhone中显示带有图像的控制器之类的弹出视图?

发布于 2024-11-09 09:10:15 字数 86 浏览 0 评论 0原文

我想在 iPhone 中显示带有图像的小型弹出视图(就像 iPad 中的弹出视图,但这里我想要在 iPhone 中)。

我怎样才能做到这一点?

I want to display small popup view (just like popup view in iPad but here I want in iPhone) in iPhone with image.

How can I do that ?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

深巷少女 2024-11-16 09:10:15

@devang你肯定会欣赏这个 http ://iosdevelopertips.com/open-source/ios-open-source-popover-api-for-iphone-wepopover.html

另一种方法是 Mehul 建议的。如果您遇到与 iPad 中的 UIPopover 相对应的内容,请告诉我们。

@devang you would certainly appreciate this http://iosdevelopertips.com/open-source/ios-open-source-popover-api-for-iphone-wepopover.html

The other approach is what Mehul suggested. Do let us know if you come across something which corresponds to UIPopover in iPad.

水水月牙 2024-11-16 09:10:15

您可以动态获取 UIView,然后在该 UIView 中添加 UIImageView,就像这样

    UIView *tmpView = [[UIView alloc] initWithFrame:CGRectMake(XPosition, YPosition, Width, Height)];       
    UIImage *tmpImg = [UIImage imageNamed:@"YourImageName.png"];
    UIImageView *tmpImgView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, tmpImg.size.width, tmpImg.size.height)];
    tmpImgView.image = tmpImg;
    [self.view addSubview:tmpView];

希望这会起作用......

You can take UIView dynamically and then add UIImageView in this UIView just like this

    UIView *tmpView = [[UIView alloc] initWithFrame:CGRectMake(XPosition, YPosition, Width, Height)];       
    UIImage *tmpImg = [UIImage imageNamed:@"YourImageName.png"];
    UIImageView *tmpImgView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, tmpImg.size.width, tmpImg.size.height)];
    tmpImgView.image = tmpImg;
    [self.view addSubview:tmpView];

Hope this will Work....

相对绾红妆 2024-11-16 09:10:15

Collectionview 可以在屏幕上弹出。下面是用于将 CollectionView 显示为弹出窗口并隐藏弹出窗口的完整代码

import UIKit

class ViewController: UIViewController , UICollectionViewDataSource, UICollectionViewDelegate  {

    //let popView = UICollectionView.init(frame: CGRect(x:8,y:30,width:304,height:200))

    var demoCollectionView:UICollectionView? = nil;

    @IBOutlet var button: UIButton!

    override func viewDidLoad() {
        super.viewDidLoad()
        // Do any additional setup after loading the view, typically from a nib.
        self.loadColorCollectionView()

    }

    func loadColorCollectionView() {
        let layout: UICollectionViewFlowLayout = UICollectionViewFlowLayout()
        layout.sectionInset = UIEdgeInsets(top: 20, left: 10, bottom: 10, right: 10)
        layout.itemSize = CGSize(width: 30, height: 30)

        demoCollectionView = UICollectionView(frame: CGRect(x:8,y:20,width:304,height:200), collectionViewLayout: layout)


        demoCollectionView?.dataSource = self
        demoCollectionView?.delegate = self
        demoCollectionView?.register(UICollectionViewCell.self, forCellWithReuseIdentifier: "Cell")
        demoCollectionView?.backgroundColor = UIColor.white
    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }

    func numberOfSections(in collectionView: UICollectionView) -> Int {
        return 1;
    }

    func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
        return 200;
    }

    func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
        let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "Cell", for: indexPath);

        if indexPath.row%2 == 0 {
        cell.backgroundColor = UIColor.red;
        }
        else{
            cell.backgroundColor = UIColor.blue;
        }
        return cell;
    }

    func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {

        guard let statusBar = UIApplication.shared.value(forKeyPath: "statusBarWindow.statusBar") as? UIView else { return }

        if indexPath.row%2 == 0 {
            statusBar.backgroundColor = UIColor.red;
        }
        else{
            statusBar.backgroundColor = UIColor.blue;
        }
        self.demoCollectionView?.removeFromSuperview()

    }

    @IBAction func showMessage() {

        //popView.backgroundColor = UIColor.darkGray;
        //self.view.addSubview(popView)


        self.view.addSubview(demoCollectionView!)
    }

    override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {
        //self.popView.removeFromSuperview()
        self.demoCollectionView?.removeFromSuperview()


    }

}

我在 Viewcontroller 中创建了一个按钮,并在按钮上调用了 showMessage() 函数,单击它将弹出一个带有颜色的 CollectionView。选择颜色时弹出窗口将消失。

Collectionview Can be popUp on screen. Below is complete code for showing collectionview as popup and hiding the popup window

import UIKit

class ViewController: UIViewController , UICollectionViewDataSource, UICollectionViewDelegate  {

    //let popView = UICollectionView.init(frame: CGRect(x:8,y:30,width:304,height:200))

    var demoCollectionView:UICollectionView? = nil;

    @IBOutlet var button: UIButton!

    override func viewDidLoad() {
        super.viewDidLoad()
        // Do any additional setup after loading the view, typically from a nib.
        self.loadColorCollectionView()

    }

    func loadColorCollectionView() {
        let layout: UICollectionViewFlowLayout = UICollectionViewFlowLayout()
        layout.sectionInset = UIEdgeInsets(top: 20, left: 10, bottom: 10, right: 10)
        layout.itemSize = CGSize(width: 30, height: 30)

        demoCollectionView = UICollectionView(frame: CGRect(x:8,y:20,width:304,height:200), collectionViewLayout: layout)


        demoCollectionView?.dataSource = self
        demoCollectionView?.delegate = self
        demoCollectionView?.register(UICollectionViewCell.self, forCellWithReuseIdentifier: "Cell")
        demoCollectionView?.backgroundColor = UIColor.white
    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }

    func numberOfSections(in collectionView: UICollectionView) -> Int {
        return 1;
    }

    func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
        return 200;
    }

    func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
        let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "Cell", for: indexPath);

        if indexPath.row%2 == 0 {
        cell.backgroundColor = UIColor.red;
        }
        else{
            cell.backgroundColor = UIColor.blue;
        }
        return cell;
    }

    func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {

        guard let statusBar = UIApplication.shared.value(forKeyPath: "statusBarWindow.statusBar") as? UIView else { return }

        if indexPath.row%2 == 0 {
            statusBar.backgroundColor = UIColor.red;
        }
        else{
            statusBar.backgroundColor = UIColor.blue;
        }
        self.demoCollectionView?.removeFromSuperview()

    }

    @IBAction func showMessage() {

        //popView.backgroundColor = UIColor.darkGray;
        //self.view.addSubview(popView)


        self.view.addSubview(demoCollectionView!)
    }

    override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {
        //self.popView.removeFromSuperview()
        self.demoCollectionView?.removeFromSuperview()


    }

}

I created a button in Viewcontroller and called showMessage() function on button click it will pop up a collectionview with colors. On select of color popup will disapear.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文