Tag: uiview

如何用IBOutlet子类化一个variables?

所有我的具体类的后代都有一个UILabel实例variables。 所以在我的父类我有var label: UILabel 。 我也想在sublclass中,但作为IBOutlet 。 我该怎么做呢? 我添加了相同名称的IBOutlet ,并对两个variables声明都添加了弱点。 但是我收到一个关于“无法用存储的属性覆盖”的错误。 我应该怎么做? 是否有可能不需要实例化超类的版本,因为我只是想要它的子类?

iOS从视图中添加/删除阴影

我不明白如何删除添加到视图中的阴影。 我在initWithFrame添加了一个这样的阴影: self.layer.borderWidth = 2; self.layer.borderColor = [UIColor clearColor].CGColor; self.backgroundColor = [UIColor greenColor]; [self.layer setCornerRadius:8.0f]; CALayer *layer = self.layer; layer.shadowOffset = CGSizeMake(2, 2); layer.shadowColor = [[UIColor blackColor] CGColor]; layer.cornerRadius = 8.0f; layer.shadowRadius = 3.0f; layer.shadowOpacity = 0.80f; layer.shadowPath = [[UIBezierPath bezierPathWithRect:layer.bounds] CGPath]; 在执行应用程序后,我想从这个视图中删除阴影。 我试过使用: layer.hidden = YES; 要么 self.layer.hidden = YES; 但是这完全隐藏了视图,而不仅仅是添加的阴影。 有没有办法从视图中检索添加的阴影,然后隐藏它? 谢谢!

关键帧animation关键时刻

我刚刚创build了一个这样的关键帧animation: [UIView animateKeyframesWithDuration:10 delay:0 options:0 animations:^{ [UIView addKeyframeWithRelativeStartTime:0 relativeDuration:.1 animations:^{ view.alpha = 0; }]; } completion:nil]; 这是一个CAKeyframeAnimation被创build: (lldb) po [self.layer animationForKey:@"opacity"] <CAKeyframeAnimation:0x10a6364b0; keyTimes = ( 0, "0.1", 1 ); values = ( 1, 0, 0 ); calculationMode = linear; delegate = <UIViewKeyframeAnimationState: 0x10a6358d0>; fillMode = both; timingFunction = easeInEaseOut; duration = 10; keyPath = opacity> […]

自定义UIView类 – Swift

我已经build立了一个视图,从底部出现,并在一段时间后隐藏,它运作良好,但我想在UIView类作为一种模式,我看着互联网,但我不明白如何做到这一点。 snake = UIView(frame: CGRect(x: 0 , y: self.view.frame.size.height-66, width: self.view.frame.size.width, height: 66)) snake.backgroundColor = UIColor(red: 50/255, green: 50/255, blue: 50/255, alpha: 1.0) let label = UILabel(frame: CGRect(x: 12, y: 8, width: snake.frame.size.width-90, height: 50)) label.text = "Connection error please try again later!!" label.textColor = UIColor.whiteColor() label.numberOfLines = 0 label.font = UIFont.systemFontOfSize(14) snake.addSubview(label) let button […]

如何在Swift中向后发送一个UIView元素

所以我有一个button,我已经在main.Storyboard中添加了一个View,然后在viewController.swift文件中,我创build了一个UIView矩形形状,我想坐在那个button后面(作为背景为它)。 问题是,当我添加矩形UIView它总是将其添加到button前面。 所以我在网上进行了研究,find了sendSubviewToBack代码。 我已经添加了这个,但是它一直发送到视图的主UIImage背景之后。 有没有办法,我可以发送这个UIView后面的button,但在UIImage背景? func nextBarDisplayed() { let theHeight = self.view.frame.height nextBar.backgroundColor = UIColor(red: 7/255, green: 152/255, blue: 253/255, alpha: 0.5) nextBar.frame = CGRect(x: 0, y: theHeight – 50, width: self.view.frame.width, height: 50) self.view.insertSubview(nextBar, aboveSubview: myBackgroundView) }

在约束依赖于框架的自定义视图中使用自动布局

我正在编写一个自定义视图,以编程方式初始化。 我重写updateConstraints以添加此视图所需的所有约束。 : – (void)updateConstraints { [self.superview addConstraint:[NSLayoutConstraint constraintWithItem:self attribute:NSLayoutAttributeCenterX relatedBy:NSLayoutRelationEqual toItem:self.superview attribute:NSLayoutAttributeCenterX multiplier:1 constant:0]]; [self.superview addConstraint:[NSLayoutConstraint constraintWithItem:self attribute:NSLayoutAttributeTop relatedBy:NSLayoutRelationEqual toItem:self.superview attribute:NSLayoutAttributeTop multiplier:1 constant:0]]; [self.superview addConstraint:[NSLayoutConstraint constraintWithItem:self attribute:NSLayoutAttributeBottom relatedBy:NSLayoutRelationEqual toItem:self.superview attribute:NSLayoutAttributeBottom multiplier:1 constant:0]]; // some more constraints, you get the point self.bottomSpacingConstraint = [NSLayoutConstraint constraintWithItem:self.imageView attribute:NSLayoutAttributeBottom relatedBy:NSLayoutRelationEqual toItem:self attribute:NSLayoutAttributeBottom multiplier:1 constant:-(0.2 * CGRectGetHeight(self.bounds))]; [self addConstraint:self.bottomSpacingConstraint]; […]

有没有办法在UIViewPropertyAnimator中观察对fractionComplete的更改

我一直在iOS 10中查看非常酷的新UIViewPropertyAnimator类。它可以让你轻松地做些事情,如暂停,恢复和反向的飞行UIViewanimation。 它曾经是,你必须操纵系统创build的底层CAAnimations为了做到这一点与UIViewanimation。 新的UIViewPropertyAnimator类有一个属性fractionComplete 。 它从0.0(animation开始)到1.0(animation结束)变化。如果更改值,则可以从头到尾“擦除”animation。 我有一个名为KeyframeViewAnimations的 Github上的演示项目,它允许您使用滑块来使用相当神秘的CAAnimation技巧来擦除UIView和CAAnimations。 当animation运行时,滑块从头到尾移动以显示animation的进度。 该项目是在Swift发布之前用Objective-C编写的,但Objective-C或Swift中的基础技术是相同的。 我决定使用UIViewPropertyAnimator创build一个等价的项目。 有一些怪癖,但是相当简单。 有一件事情我不知道如何干净地做,是观察animation的fractionComplete属性的进展,以便我可以更新滑块随着animation的进展。 我尝试在fractionComplete属性上设置KVO(键值观察),但是在animation完成之前它不会触发KVO通知。 我最终做的是设置一个计时器,它运行在一个非常小的时间间隔内,并重复查询UIViewPropertyAnimator的fractionComplete属性,并在滑动过程中更新滑块。 它可行,但这不是一个很干净的做事方式。 如果有办法获得animation进展的通知,情况会好得多。 我希望有一些我错过了。 你可以在这个链接上看到Github上基于UIViewPropertyAnimator的项目: UIViewPropertyAnimator-test 。 从animation器获取进度值的代码是这样的代码: func startTimer(_ start: Bool) { if start { timer = Timer.scheduledTimer(withTimeInterval: 0.02, repeats: true) { timer in var value = Float(self.viewAnimator.fractionComplete) if self.animatingBackwards { value = 1 – value } self.animationSlider.value = value […]

UIView中的黑色背景?

我在网上跟随一个教程来绘制一个子类UIView。 本教程展示了一个带有白色背景的UIView,我通过简单的改变super的bg颜色来解决这个问题。 问题是,当触摸结束时,背景不清晰。 我不知道。 我只是试图设置填充颜色[uicolor clearcolor]; 不成功。 这是我正在使用的代码: @implementation CachedLIView { UIBezierPath *path; UIImage *incrementalImage; // (1) } – (id)initWithCoder:(NSCoder *)aDecoder { if (self = [super initWithCoder:aDecoder]) { [self setMultipleTouchEnabled:NO]; [self setBackgroundColor:[UIColor whiteColor]]; path = [UIBezierPath bezierPath]; [path setLineWidth:2.0]; } return self; } – (void)drawRect:(CGRect)rect { [incrementalImage drawInRect:rect]; // (3) [path stroke]; } – (void)touchesBegan:(NSSet […]

只为UIView的一部分设置背景颜色

我想我的UIView底部(不是一半)是一个不同的颜色比顶部。 我想知道如果我应该创build一个CGRect,然后颜色? 这是沿着正确的轨道? – (void)drawRect:(CGRect)rect { CGRect aRect = CGRectMake(x, y, width, height); // Fill the rectangle with grey [[UIColor greyColor] setFill]; UIRectFill( rect ); }

制作一个固定大小的UIView,就像UISwitch(使用IBDesignable)

当我使用本指南创build一个在XIB中devise的视图时,可以使用我的UIView子类上的IBDesignable属性在故事板中重用,如何使其具有固定的大小,并使其大小调整行为与像UISwitch的观点? 与“调整行为”我也意味着在界面生成器devise。