gpt4 book ai didi

ios - 快速更改 uiimageview 背景颜色

转载 作者:行者123 更新时间:2023-11-28 08:56:58 25 4
gpt4 key购买 nike

![the result screenshot--][http://i.stack.imgur.com/4YRAJ.png]我想像后面那样改变 ![enter image description here][http://i.stack.imgur.com/cBMsJ.png]当滑动条打开时,我想让滑动条后面的背景变暗以覆盖 UIimageview,但是除了 UIimageView 之外的背景都变暗了。有什么方法可以使图像变暗吗?

   //
// ViewController.swift
// SideBarMenu
//
// Created by Alexandre on 30/01/2015.
// Copyright (c) 2015 Alexandre. All rights reserved.
//

import UIKit
import Social

class ViewController: UIViewController, SideBarDelegate {

@IBOutlet weak var backgroundView: UIView!
@IBOutlet weak var hedgeImage: UIImageView!

func sideBarWillOpen() {
/* let blurEffect = UIBlurEffect(style: UIBlurEffectStyle.Light)
let blurView = UIVisualEffectView(effect: blurEffect)
blurView.frame = CGRectMake(0,0, 200, backgroundView.frame.size.height)
backgroundView.addSubview(blurView)*/

backgroundView.backgroundColor = UIColor.grayColor()
hedgeImage.backgroundColor = UIColor.grayColor()
}

func sideBarWillClose() {
backgroundView.backgroundColor = UIColor.whiteColor()
// hegeImage.backgroundColor = UIColor.whiteColor()
}

最佳答案

实现这一点的一种方法是,您可以在所有 View 之上再添加一个 View 并将该 View 颜色设置为 grayColor 并在开始时隐藏它并将其 alpha 设置为 0.8 和当侧边栏出现时显示该 View ,当侧边栏隐藏时您可以隐藏该 View 。

这是为您准备的简单示例代码:

import UIKit

class ViewController: UIViewController, sideBarDelegate {

var sideBar : SideBar = SideBar()

@IBOutlet weak var TransperentView: UIView!
@IBOutlet weak var imageView: UIImageView!
override func viewDidLoad() {
super.viewDidLoad()
TransperentView.hidden = true
TransperentView.alpha = 0.8
TransperentView.backgroundColor = UIColor.grayColor()
sideBar = SideBar(sourceView: self.view, menuIteams: ["FirstIteam","SecondIteam","ThirdIteam","FourthIteam"])
sideBar.delegate = self
}

func sideBarDidSelectButtonAtIndex(index: Int) {

sideBar.showSideBar(false)
TransperentView.hidden = true //hide view
}
@IBAction func index(sender: AnyObject) {

TransperentView.hidden = false
sideBar.showSideBar(true) //show view

}
}

结果将是:

enter image description here

HERE是更多信息的示例项目。

关于ios - 快速更改 uiimageview 背景颜色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32794493/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com