Tag: uiview

如何在UIView的顶端添加一个边框

我的问题是在标题上。 我不知道如何添加边框在特定的一面,顶部或底部,任何一方… layer.border绘制整个视图的边框…

什么是强制UIView重绘最强大的方法?

我有一个项目列表的UITableView。 select一个项目推一个viewController,然后继续执行以下操作。 从方法viewDidLoad我发射一个URLRequest为我的子视图所需的数据 – 一个UIView子类与drawRect覆盖。 当数据从云端到达时,我开始构build我的视图层次结构。 有问题的子类传递数据,它的drawRect方法现在拥有了它需要呈现的所有东西。 但。 因为我不明确调用drawRect – Cocoa-Touch处理 – 我没有办法通知Cocoa-Touch,我真的很想要这个UIView子类来呈现。 什么时候? 现在会很好! 我试过[myView setNeedsDisplay]。 有时这种工作。 很斑点。 我已经摔了几个小时。 有谁可以请我提供一个坚实的,有保证的方法来强制UIView重新渲染。 以下是将数据提供给视图的代码片段: // Create the subview self.chromosomeBlockView = [[[ChromosomeBlockView alloc] initWithFrame:frame] autorelease]; // Set some properties self.chromosomeBlockView.sequenceString = self.sequenceString; self.chromosomeBlockView.nucleotideBases = self.nucleotideLettersDictionary; // Insert the view in the view hierarchy [self.containerView addSubview:self.chromosomeBlockView]; [self.containerView bringSubviewToFront:self.chromosomeBlockView]; // […]

UIView的setNeedsLayout,layoutIfNeeded和layoutSubviews之间有什么关系?

任何人都可以给UIView's setNeedsLayout , layoutIfNeeded和layoutSubviews方法之间的关系明确的解释? 以及所有三个将被使用的示例实现。 谢谢。 让我感到困惑的是,如果我发送自定义视图setNeedsLayout消息,那么它在layoutSubviews之后调用的下一个东西将跳过layoutIfNeeded 。 从文档我希望stream程setNeedsLayout >导致layoutIfNeeded调用>导致layoutSubviews被调用。

了解convertRect:toView :, convertRect:FromView:,convertPoint:toView:和convertPoint:fromView:方法

我试图了解这些方法的function。 你能否给我提供一个简单的用例来理解他们的语义? 从文档中,例如, convertPoint:fromView:方法描述如下: 将给定视图的坐标系中的点转换为接收者的点。 坐标系是什么意思? 接收机怎么样? 例如,是否有意义使用convertPoint:fromView:如下所示? CGPoint p = [view1 convertPoint:view1.center fromView:view1]; 使用NSLog实用程序,我已经validation了p值与view1的中心一致。 先谢谢你。 编辑:对于那些感兴趣的,我已经创build了一个简单的代码片段来理解这些方法。 UIView* view1 = [[UIView alloc] initWithFrame:CGRectMake(100, 100, 150, 200)]; view1.backgroundColor = [UIColor redColor]; NSLog(@"view1 frame: %@", NSStringFromCGRect(view1.frame)); NSLog(@"view1 center: %@", NSStringFromCGPoint(view1.center)); CGPoint originInWindowCoordinates = [self.window convertPoint:view1.bounds.origin fromView:view1]; NSLog(@"convertPoint:fromView: %@", NSStringFromCGPoint(originInWindowCoordinates)); CGPoint originInView1Coordinates = [self.window convertPoint:view1.frame.origin toView:view1]; NSLog(@"convertPoint:toView: %@", […]

改变我的CALayer的anchorPoint移动视图

我想改变anchorPoint ,但保持视图在同一个地方。 我已经试过NSLog -ing self.layer.position和self.center ,他们都保持不变的anchorPoint不变。 然而,我的观点在动! 有关如何做到这一点的任何提示? self.layer.anchorPoint = CGPointMake(0.5, 0.5); NSLog(@"center point: %f %f", self.layer.position.x, self.layer.position.y); self.layer.anchorPoint = CGPointMake(1, 1); NSLog(@"center point: %f %f", self.layer.position.x, self.layer.position.y); 输出是: 2009-12-27 20:43:24.161 Type[11289:207] center point: 272.500000 242.500000 2009-12-27 20:43:24.162 Type[11289:207] center point: 272.500000 242.500000

Autolayout – UIButton的内在大小不包括标题插入

如果我有一个UIButton使用自动布局排列,其大小调整很好,以适应其内容。 如果我设置一个图像为button.image ,内在大小似乎再次考虑到这一点。 但是,如果我调整button的titleEdgeInsets ,布局不会考虑这个,而是截断button标题。 我怎样才能确保button的内在宽度占内嵌? 编辑: 我正在使用以下内容: [self.backButton setTitleEdgeInsets:UIEdgeInsetsMake(0, 5, 0, 0)]; 目标是在图像和文本之间添加一些分隔。

UIlabel layer.cornerRadius无法在iOS 7.1中使用

我目前正在寻找与属性addMessageLabel.layer.cornerRadius = 5.0f;的UILabel addMessageLabel.layer.cornerRadius = 5.0f; 在安装有iOS 7.0的设备上,它具有圆angular。 在装有iOS 7.1的设备上,它没有圆angular。 这只是一个与iOS 7.1的错误?

UIView的框架,边界,中心,出处,什么时候用什么?

UIView具有属性frame , bounds , center和origin ,它们似乎都是相互关联的。 大多数时候,我在设置UIView的位置和大小时处理frame 。 我知道frame是使用全局坐标系, bounds是使用本地视图的坐标(因此它的x和y是0,但并不总是),但是当我使用什么时,它仍然是令人困惑的。 在什么情况下(以及什么是正确的时间),应该使用其他属性( bounds , center , origin )?

如何设置iPhone UIView z索引?

我想移动另一个视图,我怎么能知道视图的z索引,以及如何移动到顶部?

如何将触摸事件添加到UIView?

如何添加触摸事件到UIView? 我尝试: UIView *headerView = [[[UIView alloc] initWithFrame:CGRectMake(0, 0, tableView.bounds.size.width, nextY)] autorelease]; [headerView addTarget:self action:@selector(myEvent:) forControlEvents:UIControlEventTouchDown]; // ERROR MESSAGE: UIView may not respond to '-addTarget:action:forControlEvents:' 我不想创build一个子类和覆盖 – (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event