我有一个带有圆角和阴影的 UIView,已实现并正在工作。但是 UIView 有一个无聊的背景颜色,白色。所以我想放一个渐变层作为背景。在标签、按钮下方,最重要的是,使圆角仍然出现。
CAGradientLayer *gradient = [CAGradientLayer layer];
gradient.frame = subHudView.bounds;
gradient.colors = [NSArray arrayWithObjects:(id)[[UIColor blackColor] CGColor], (id)[[UIColor whiteColor] CGColor], nil];
[subHudView.layer addSublayer:gradient];
subHudView.layer.cornerRadius = 8;
subHudView.layer.masksToBounds = NO;
subHudView.layer.shadowOffset = CGSizeMake(-5, 5);
subHudView.layer.shadowRadius = 8;
subHudView.layer.shadowOpacity = 0.75;
Run Code Online (Sandbox Code Playgroud)
这是我尝试实现的代码,但渐变层位于视图中的所有内容之上。如何使渐变在所有控件和标签下显示?每一个回应的帮助将不胜感激。
这是一个使用轮播的页面(我相信 flexslider)。此旋转木马中的图像不是背景图像。我需要为图像添加一个渐变,从下到上,从暗到零不透明度,以便我可以使文本更清晰。这可能吗?
我有一张图片就在这里:

我想在网站theverge.com上复制css样式(见下图)

我会在我的博客中(在主页面中)使用它,因为我试图复制theverge.com网站的内容.就像在半透明渐变和特色图像上使用帖子的标题和作者的名字一样.
请帮忙.
这是我的HTML的结构
http://jsfiddle.net/Kareen/kwPP8/2/
<div class="content">
<h3>Some Title Goes Here</h3>
<div>Author: Bill Jones</div>
<img src="http://lorempixel.com/300/200/nature/5" />
</div>
Run Code Online (Sandbox Code Playgroud) 我将此 css 应用于我的 DIV
div#envelope{
width: 400px;
margin: 140px 23% 10px 16%;
padding:33px 0 10px 0;
border-radius:2px;
background-color: rgba(255,255,255,0.5);
background-image: -webkit-gradient(
linear,
right bottom,
left top,
color-stop(0, rgba(255, 255, 255, 0.5)),
color-stop(0.50, rgba(255, 255, 255, 0.5))
);
background-image: -o-linear-gradient(left top, rgba(255, 255, 255, 1) 0%, rgba(255, 255, 255, 0.5) 50%);
background-image: -moz-linear-gradient(left top, rgba(255, 255, 255, 1) 0%, rgba(255, 255, 255, 0.5) 50%);
background-image: -webkit-linear-gradient(left top, rgba(255, 255, 255, 1) 0%, rgba(255, 255, 255, 0.5) 50%);
background-image: -ms-linear-gradient(left top, rgba(255, …Run Code Online (Sandbox Code Playgroud) 我正在尝试为UILabel绘制渐变,但它只会绘制我看不到文本的颜色。我看到的代码从这里的StackOverflow
我的修改:
extension String{
func gradient(x:CGFloat,y:CGFloat, fontSize:CGFloat)->UIImage{
let font:UIFont = UIFont.systemFontOfSize(fontSize)
let name:String = NSFontAttributeName
let textSize: CGSize = self.sizeWithAttributes([name:font])
let width:CGFloat = textSize.width // max 1024 due to Core Graphics limitations
let height:CGFloat = textSize.height // max 1024 due to Core Graphics limitations
UIGraphicsBeginImageContext(CGSizeMake(width, height))
let context = UIGraphicsGetCurrentContext()
UIGraphicsPushContext(context!)
//draw gradient
let glossGradient:CGGradientRef?
let rgbColorspace:CGColorSpaceRef?
let num_locations:size_t = 2
let locations:[CGFloat] = [ 0.0, 1.0 ]
let components:[CGFloat] = [(202 / 255.0), (197 / 255.0), (52 / …Run Code Online (Sandbox Code Playgroud) 我有这个扩展,在Swift中为一个视图添加一个渐变:
extension UIView {
func addGradientWithColor(colorTop: UIColor, colorButton: UIColor){
let gradient = CAGradientLayer()
gradient.frame = self.bounds
gradient.colors = [colorTop.cgColor, colorButton.cgColor]
self.layer.insertSublayer(gradient, at: 0)
}
}
Run Code Online (Sandbox Code Playgroud)
然后,我在我的UIViewController中使用它:
override func viewDidLoad(){
self.view.addGradientWithColor(colorTop: UIColor.red, colorButton: UIColor.clear)
super.viewDidLoad()
}
Run Code Online (Sandbox Code Playgroud)
我运行模拟器,效果很好.但是,当我想在真实设备上使用我的应用程序时,Gradient不起作用.
PD:我尝试了许多方法来做一个Gradient,但在真实设备上没有任何效果.
我试图tf.gradient在张量流y中做出一个hack,它会给出一个等级(M,N)的张量和一个x等级(Q,P)的等级(M,N,Q,P)的梯度张量作为一个自然会期待.
正如在这个网站*上的多个问题所指出的那样,得到的是一个等级(Q,P),它是元素总和的等级y.现在我无法弄清楚,查看张量流代码是在哪里对元素进行求和y?是开始还是结束?有人可以帮我查明代码行吗?
*
我有一个 UIButton。我想设置按钮的渐变如下。
我试过下面的代码,但它没有按照屏幕截图设置颜色。
func applyGradient(colours: [UIColor]) -> Void {
self.applyGradient(colours: colours, locations: nil)
}
func applyGradient(colours: [UIColor], locations: [NSNumber]?) -> Void {
let gradient: CAGradientLayer = CAGradientLayer()
gradient.frame = self.bounds
gradient.colors = colours.map { $0.cgColor }
gradient.locations = locations
self.layer.insertSublayer(gradient, at: 0)
}
Run Code Online (Sandbox Code Playgroud) 我正在使用Pixi.js v4 图形库用 JavaScript 制作游戏。我知道我可以像这样绘制一个黑色 + 圆角矩形:
const rectangle = new pixi.Graphics();
rectangle.beginFill(0); // Color it black
rectangle.drawRoundedRect(
0,
0,
100, // Make it 100x100
100,
5, // Make the rounded corners have a radius of 5
);
rectangle.endFill();
stage.addChild(rectangle);
Run Code Online (Sandbox Code Playgroud)
如何绘制一个从白到黑渐变的圆角矩形?
如何绘制具有逐渐不透明度的圆角矩形,使其从左到右淡入?