MPVolumeView 更改 Airplay 图标的大小

发布于 2024-10-16 21:23:55 字数 136 浏览 0 评论 0 原文

我的一个视图上有一个 MPVolumeView,当有其他可用的输出源时,它会显示一个 Airplay 图标。这一切都很好,但是图标很小,无论我为 MPVolumeView 设置多大的框架,它都不会变得更大。

有人知道如何增加播放图标的大小吗?

I have an MPVolumeView on one of my views, which comes up with an Airplay icon when there are other output sources available. That's all fine, but the icon is tiny, no matter how big I set the frame for MPVolumeView it doesn't get any bigger.

Anyone know how to increase the size of the airplay icon?

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

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

发布评论

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

评论(3

那些过往 2024-10-23 21:23:55

我这样做只是为了显示图标并增加其大小:

MPVolumeView *volumeView = [[[MPVolumeView alloc] initWithFrame:CGRectMake(255, 12, 30, 25)] autorelease];
volumeView.showsVolumeSlider = NO;
volumeView.showsRouteButton = YES;
volumeView.transform = CGAffineTransformMakeScale(1.5, 1.5); // increase size by 50%

I did this to just show the icon and increase its size:

MPVolumeView *volumeView = [[[MPVolumeView alloc] initWithFrame:CGRectMake(255, 12, 30, 25)] autorelease];
volumeView.showsVolumeSlider = NO;
volumeView.showsRouteButton = YES;
volumeView.transform = CGAffineTransformMakeScale(1.5, 1.5); // increase size by 50%
浅忆 2024-10-23 21:23:55

至少现在,您所能做的就是抓取子视图并手动设置大小。这可能不是一个好主意,因为子视图层次结构可能会发生变化,即使您为图标设置了更大的框架,它也不会变大(或者如果 contentMode 设置为拉伸,您会得到一个模糊的图标)

您可能甚至可以手动将图标替换为在应用程序中提供的较大图标,但让我再说一遍,这不是一个好主意。

At least for now, all you can do is crawling the subviews and manually set the size. It's probably not a good idea, as subview hierarchy is suspect to change, and even if you set a bigger frame for the icon, it won't get bigger (or if contentMode is set to stretch, you get a blurred icon)

You may even be able to manually replace the icon with a larger one that you provide in your app, but let me say this again, it's not a good idea.

美煞众生 2024-10-23 21:23:55

爬行子视图并使用约束,我成功地复制了 AVRoutePickerView 的行为,它根据其包含的视图调整图标图像的大小。

尽管需要通过 setRouteButtonImage(第二张图片) 使用自定义图标。如果没有,它会使用 2 个不显示调整大小的离子的 ImageView(第一张图像)。

接下来附上代码和视图层次结构:

class ViewController: UIViewController {

    @IBOutlet weak var airplayView: MPVolumeView!

    override func viewDidLoad() {
        super.viewDidLoad()
        airplayView.showsRouteButton = true
        airplayView.showsVolumeSlider = false
        airplayView.setRouteButtonImage(UIImage(named: "airplay"), for: .normal)
        for view in airplayView.subviews {
            if let button = view as? UIButton {
                button.imageView?.contentMode = .scaleAspectFit
                button.translatesAutoresizingMaskIntoConstraints = false
                NSLayoutConstraint(item: button,
                                   attribute: NSLayoutConstraint.Attribute.bottom,
                                   relatedBy: NSLayoutConstraint.Relation.equal,
                                   toItem: airplayView,
                                   attribute: NSLayoutConstraint.Attribute.bottom,
                                   multiplier: 1,
                                   constant: 0).isActive = true
                NSLayoutConstraint(item: button,
                                   attribute: NSLayoutConstraint.Attribute.trailing,
                                   relatedBy: NSLayoutConstraint.Relation.equal,
                                   toItem: airplayView,
                                   attribute: NSLayoutConstraint.Attribute.trailing,
                                   multiplier: 1,
                                   constant: 0).isActive = true
                NSLayoutConstraint(item: button,
                                   attribute: NSLayoutConstraint.Attribute.top,
                                   relatedBy: NSLayoutConstraint.Relation.equal,
                                   toItem: airplayView,
                                   attribute: NSLayoutConstraint.Attribute.top,
                                   multiplier: 1,
                                   constant: 0).isActive = true
                NSLayoutConstraint(item: button,
                                   attribute: NSLayoutConstraint.Attribute.leading,
                                   relatedBy: NSLayoutConstraint.Relation.equal,
                                   toItem: airplayView,
                                   attribute: NSLayoutConstraint.Attribute.leading,
                                   multiplier: 1,
                                   constant: 0).isActive = true
            }
        }
    }
}

使用系统图标
使用自定义图标

Crawling the subviews and using constraints I've manage to replicate the behaviour of AVRoutePickerView, which resizes icon image according to its containing view.

Although it's needed to use a custom icon via setRouteButtonImage(second image). If not, it uses 2 ImageView that don't show the ion resized (first image).

Code and View Hierarchy attached next:

class ViewController: UIViewController {

    @IBOutlet weak var airplayView: MPVolumeView!

    override func viewDidLoad() {
        super.viewDidLoad()
        airplayView.showsRouteButton = true
        airplayView.showsVolumeSlider = false
        airplayView.setRouteButtonImage(UIImage(named: "airplay"), for: .normal)
        for view in airplayView.subviews {
            if let button = view as? UIButton {
                button.imageView?.contentMode = .scaleAspectFit
                button.translatesAutoresizingMaskIntoConstraints = false
                NSLayoutConstraint(item: button,
                                   attribute: NSLayoutConstraint.Attribute.bottom,
                                   relatedBy: NSLayoutConstraint.Relation.equal,
                                   toItem: airplayView,
                                   attribute: NSLayoutConstraint.Attribute.bottom,
                                   multiplier: 1,
                                   constant: 0).isActive = true
                NSLayoutConstraint(item: button,
                                   attribute: NSLayoutConstraint.Attribute.trailing,
                                   relatedBy: NSLayoutConstraint.Relation.equal,
                                   toItem: airplayView,
                                   attribute: NSLayoutConstraint.Attribute.trailing,
                                   multiplier: 1,
                                   constant: 0).isActive = true
                NSLayoutConstraint(item: button,
                                   attribute: NSLayoutConstraint.Attribute.top,
                                   relatedBy: NSLayoutConstraint.Relation.equal,
                                   toItem: airplayView,
                                   attribute: NSLayoutConstraint.Attribute.top,
                                   multiplier: 1,
                                   constant: 0).isActive = true
                NSLayoutConstraint(item: button,
                                   attribute: NSLayoutConstraint.Attribute.leading,
                                   relatedBy: NSLayoutConstraint.Relation.equal,
                                   toItem: airplayView,
                                   attribute: NSLayoutConstraint.Attribute.leading,
                                   multiplier: 1,
                                   constant: 0).isActive = true
            }
        }
    }
}

Using system icon
Using custom icon

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