Tag: 客观

自定义UITableViewCell与图像突出显示

我有一个自定义的UITableViewCell(从XIB实例化)与图像作为背景。 现在我想要另一个图像作为select单元格的背景(类似于标准单元格的蓝色闪烁)。 我已经尝试使用setSelectedBackgroundView设置(void)setSelected:(BOOL)selected animated:(BOOL)animated ,甚至在didSelectRowAtIndexPath但突出显示的背景不会显示。 我究竟做错了什么?

观察UIView更改崩溃

我已经使用下面的代码来确定视图何时被添加到超级视图: //Makes views announce their change of superviews Method method = class_getInstanceMethod([UIView class], @selector(willMoveToSuperview:)); IMP originalImp = method_getImplementation(method); void (^ block)(id, UIView *) = ^(id _self, UIView *superview) { [_self willChangeValueForKey:@"superview"]; originalImp(_self, @selector(willMoveToSuperview:), superview); [_self didChangeValueForKey:@"superview"]; }; IMP newImp = imp_implementationWithBlock((__bridge id)((__bridge void*)block)); method_setImplementation(method, newImp); 我没有任何问题,但是当我尝试运行在64位 ,我得到 originalImp(_self,@selector(willMoveToSuperview :),superview)上的EXC_BAD_ACCESS(code = EXC_I386_GPFLT); 任何人有任何见解? 谢谢

如何比较PHAsset到UIImage

我已经将一些PHAsset转换为UIImage : PHImageManager *manager = [PHImageManager defaultManager]; [manager requestImageForAsset:asset targetSize:PHImageManagerMaximumSize contentMode:PHImageContentModeDefault options:requestOptions resultHandler:^void(UIImage *image, NSDictionary *info) { convertedImage = image; [images addObject:convertedImage]; }]; 现在我想要做这样的事情: [selectedAssets removeObject:image]; 其中selectedAssets是PHAsset的数组, image是UIImage 所以我实现了这样的isEqual: – (BOOL)isEqual:(id)other { if (other == self) return YES; if (!other || ![[other class] isEqual:[self class]]) return NO; NSData *data1 = UIImagePNGRepresentation(self.image); NSData *data2 = UIImagePNGRepresentation(((TINSelectedImage*)other).image); […]

如何混合两个图像?

在我看来,我有两个图像,我需要混合这两个图像。 但问题是无法得到完美的融合。 代码为图像混合 CGSize newSize = CGSizeMake(_backGroundImage.frame.size.width, _backGroundImage.frame.size.height); UIGraphicsBeginImageContext( newSize ); [_backGroundImage.image drawInRect:CGRectMake(_backGroundImage.frame.origin.x,_backGroundImage.frame.origin.y,_backGroundImage.frame.size.width,_backGroundImage.frame.size.height) blendMode:kCGBlendModeNormal alpha:1.0]; [_foreGroundImage.image drawInRect:CGRectMake(_foreGroundImage.frame.origin.x,_foreGroundImage.frame.origin.y,_foreGroundImage.frame.size.width,_foreGroundImage.frame.size.height) blendMode:kCGBlendModeColor alpha:0.5]; UIImage *newImage = UIGraphicsGetImageFromCurrentImageContext(); UIGraphicsEndImageContext(); [_resultImage setImage:newImage ]; 我也尝试了不同的混合模式,但无法得到结果。 请帮我解决这个问题

打开自定义的UITableViewCell时,显示/隐藏溢出菜单中的辅助function元素

我在自定义的UITableViewCell类中实现可访问性。 我有一个相当简单的溢出菜单,里面有几个button,直到按下一个省略号button,滑动打开并closures溢出。 在我的单元格的初始化程序中,我将overflowContainer的accessibilityElementsHidden设置为YES 。 这似乎工作,当滚动使用VoiceOver,这些意见被跳过。 然后,当打开单元格时,在UIViewanimation的完成处理程序中,我将同一个overflowContainer相同的accessibilityElementsHidden设置为NO。 这似乎没有任何影响,这些元素仍然跳过。 我也曾尝试在更改accessibilityElementsHidden BOOL之前/之后/更改accessibilityElementsHidden BOOL时发布UIAccessibilityPostNotification(UIAccessibilityLayoutChangedNotification, nil) ,但是这对此情况似乎也没有影响。 基本上我想切换一些UIView实例在特定点的accessibilityElementsHidden 。 谁能让我知道我可能做错了什么? 这是我打开溢出时触发的代码: – (void)cellOverflowDidShow:(MyCell *)cell { self.overflowContainer.isAccessibilityElement = YES; self.firstButton.isAccessibilityElement = YES; self.secondButton.isAccessibilityElement = YES; self.thirdButton.isAccessibilityElement = YES; UIAccessibilityPostNotification(UIAccessibilityLayoutChangedNotification, self.firstButton); } closures单元格时,我将相反的方向(全部设置为NO并再次发布通知)。 当初始化单元格时,我设定的是: self.overflowContainer.isAccessibilityElement = NO; 绝对不知道为什么它不应该工作,看来我正在做的一切100%正确。 如果我没有在初始化程序中设置行,所有button都可以访问(始终)。 所以看起来,第一个电话,不pipeYES还是NO ,都可以工作,但是随后的电话都会被忽略。

我如何可以自定义borderWidth的所有UITextField外观?

我正在尝试为borderWith定制所有UITextField外观。 尝试这样的事情。 只有前两行有所作为。 其余的线路不工作? [[UITextField appearance] setBackgroundColor:[UIColor greenColor]]; [[UITextField appearance] setTextColor:[UIColor blackColor]]; [UITextField appearance].layer.cornerRadius = 6.0f; [UITextField appearance].layer.borderColor = [UIColor redColor].CGColor; [UITextField appearance].layer.borderWidth = 3.f;

UISegmentedControl中的自定义字体禁用adjustsFontSizeToFitWidth

我为我的UISegmentedControl设置了自定义字体,但似乎禁用了默认的autoAdjustFontSizeToFitWidth参数。 之前: 后: 以下是我应用于设置自定义字体的代码: UISegmentedControl *segmentedControl = (UISegmentedControl *)subview; UIFont *font = [UIFont fontWithName:DEFAULT_FONT size:DEFAULT_FONT_SIZE]; NSDictionary *attributes = [NSDictionary dictionaryWithObject:font forKey:NSFontAttributeName]; [segmentedControl setTitleTextAttributes:attributes forState:UIControlStateNormal]; 有没有办法保存它? 非常感谢。 编辑:我想避免 segmentedControl.apportionsSegmentWidthsByContent = YES; 如果可能的话,每个细分总是有相同的宽度。

插入或删除多个项目时,UICollectionView速度非常慢

我试图从一个集合视图中插入和删除大量的项目(比如20,000),这个操作需要很长时间。 我创build的testing夹具由以下部分组成: UICollectionView除了数据源之外没有configuration。 默认的UICollectionViewFlowLayout 。 根据BOOLvariables返回10K或30K项目的数据源。 button来切换该variables。 当设置为YES ,20K项目正在被添加到数据源(通过改变numberOfItemsInSection:和insertItemsAtIndexPaths:被添加到20K项目。 当设置为NO ,将调用deleteItemsAtIndexPaths: 20K项目。 数据源中的单元configuration除了UICollectionViewCell默认的UICollectionViewCell并返回它外,什么都不做。 在模拟器上运行这个应该比任何设备都快的模拟器产生以下时序: 插入20K项目:220ms。 删除相同的20K项目:1100毫秒。 无论如何,这是非常缓慢的,特别是在主线上执行的时候。 下面是仪器的屏幕截图,显示了UICollectionView内部实现中的热点(具体来说_computeItemUpdates ): 我注意到使用reloadData而不是插入或更新项目是更快的方法(〜20ms),可能是因为没有animation触发,所以不需要计算每个项目和部分的animation位置的位置。 任何想法如何克服这将不胜感激。

在滚动后删除CALayer到UITableViewCell

我正在尝试将CALayer添加到我的UITableViewCell的底部以获得一些“影子”效果。 问题是当表格向上滚动并移出图层时,所以当你向下滚动时,它不可见。 如果从屏幕向下滚动单元格,然后备份,他们显得很好。 我有一个GIF在这里显示发生了什么事情。 这是我如何做到这一点: – (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { static NSString *cellIdentifier = @"CellIdentifier"; UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier]; if (!cell) { cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdentifier]; } cell.textLabel.text = [NSString stringWithFormat:@"Row %d", (int)indexPath.row]; CALayer *bottomBorder = [CALayer layer]; bottomBorder.frame = CGRectMake(0.0f, cell.frame.size.height, cell.frame.size.width, 1.0f); bottomBorder.backgroundColor = [UIColor colorWithWhite:0.9f alpha:1.0f].CGColor; [cell.layer […]

如何添加取消select到UICollectionView但没有多个select?

我目前有一个视图有4个不同的采集视图,我想允许取消select。 为此,我必须设置: //Stop multiple selections on collectionview self.bagsCollectionView.allowsMultipleSelection = YES; self.shoesCollectionView.allowsMultipleSelection = YES; self.dressesCollectionView.allowsMultipleSelection = YES; self.jewelleryCollectionView.allowsMultipleSelection = YES; 不过,我只想从每个collectionview中select一个单元格。 例如,在bagsCollectionView中,用户可以select一个包,但也可以取消select另一个包。 他们不能挑两个袋子或两个鞋子。 其他三个收集意见也一样! 我该怎么做呢?