- iOS/Objective-C 元类和类别
- objective-c - -1001 错误,当 NSURLSession 通过 httpproxy 和/etc/hosts
- java - 使用网络类获取 url 地址
- ios - 推送通知中不播放声音
我有一个 UIScrollView,其中有 500 多个自定义按钮,根据用户的要求,它最多可以达到 1000 个。实际上,是 UIButton 的子类。我使用 UIButton 类的原因是我必须在点击时执行一些操作。该对象看起来像下图
这些按钮的排列就像 m*n 矩阵,其中行 (m) 固定为 20,但列 (n) 不固定。可以有 500 列。
我的问题是添加按钮后 scrollView 运行不流畅。我使用以下代码来创建每个对象
- (id)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self) {
// Initialization code
sizeLabel = [[UILabel alloc] initWithFrame:sizeLabelRect];
sizeLabel.font = [UIFont boldSystemFontOfSize:sizeLabelFontSize];
sizeLabel.textAlignment = UITextAlignmentCenter;
// sizeLabel.backgroundColor = [self colorWithHexString:LABEL_BG_COLOR];
// sizeLabel.layer.cornerRadius = CORNER_RADIUS;
[self addSubview:sizeLabel];
nFilesLabel = [[UILabel alloc] initWithFrame:nFilesLabelRect];
nFilesLabel.font = [UIFont boldSystemFontOfSize:nFilesFontSize];
nFilesLabel.textAlignment = UITextAlignmentCenter;
// nFilesLabel.backgroundColor = [self colorWithHexString:LABEL_BG_COLOR];
// nFilesLabel.layer.cornerRadius = CORNER_RADIUS;
[self addSubview:nFilesLabel];
maxDisimilarity = [[UILabel alloc] initWithFrame:disimilarityRect];
// maxDisimilarity.layer.cornerRadius = CORNER_RADIUS;
[self addSubview:maxDisimilarity];
// nFragment = [[UILabel alloc] init];
// nFragment.font = [UIFont systemFontOfSize:nFragmentFontSize];
// [self addSubview:nFragment];
}
return self;
}
/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect
{
// Drawing code
}
*/
- (void)setObj:(CloneClass *)obj
{
NSString *colorCode;
if (obj != nil) {
_obj = obj;
if ([_obj.type isEqualToString:@"1"]) {
colorCode = COLOR;
} else if ([_obj.type isEqualToString:@"2"]) {
colorCode = COLOR;
} else if ([_obj.obj isEqualToString:@"Type-3"]) {
colorCode = COLOR;
}
self.backgroundColor = [self colorWithHexString:colorCode];
[self setTitle:[NSString stringWithFormat:@"%d", obj.nFragments] forState:UIControlStateNormal];
// set size of clone class
if (_obj.size > LARGE_SIZE) {
sizeLabel.text = LARGE_SIZE_TEXT;
} else if (_obj.size > MEDIUM_SIZE && _obj.size <= LARGE_SIZE) {
sizeLabel.text = MEDIUM_SIZE_TEXT;
} else {
sizeLabel.text = SMALL_SIZE_TEXT;
}
// set number of files within a clone class
nFilesLabel.text = [NSString stringWithFormat:@"%d", _cloneClass.nFiles];
// set color for disimilarity
CGFloat similarity = 1.0 - _cloneClass.maxDisimilarity;
maxDisimilarity.backgroundColor = [UIColor colorWithRed:1.0 green:similarity blue:similarity alpha:1.0];
} else {
self.backgroundColor = [UIColor grayColor];
[self setTitle:@"/" forState:UIControlStateNormal];
}
self.titleLabel.textColor = [UIColor blackColor];
}
ScrollView 甚至不适用于 10*10 矩阵。
提前致谢
最佳答案
我会查看 UICollectionView
。你现在会遇到内存问题。 UICollectionView
允许您创建一个类似于 UITableViewCell
的 UICollectionViewCell
,可以重复使用。
参见 Apple Documentation .
关于ios - 添加自定义按钮后 UIScrollView 运行不流畅,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15940506/
我想在单击按钮时进行移动:向左。这是针对移动运动的... 问题在于它的移动,但只有一次。我需要点击按钮发送垃圾邮件... 代码: 在创建中: this.buttonleft.inputEnabled
前言 今天大姚给大家分享一个.NET开源(MIT License)、免费、现代化、流畅、可测试、可移植的URL构建器和HTTP客户端库:Flurl。 项目介绍 Flurl是一个集现代性、流畅性、
我不确定其他与我的问题明显相似的问题是否归结为同一主题。 请考虑这段代码(为更清楚起见,为 head 部分提取了 CSS 代码): body { margin: 0;
我是一名学习 html/css 的学生,我在创建第一个网站时遇到了问题。我在配置页面时遇到了很多困难,因此它是流动的而不是固定的。我配置了一个框、图像和一些文本,因此它们在页面上是绝对的,但我无法使页
在我的游戏中,我已将角色设置为移动。它的设置方式是: if game_over_state == False: if event.type == pygame.KEYDOWN:
我一直在研究代码,但似乎无法让它工作。我用谷歌搜索,在这个网站上搜索了 13 页,但仍然找不到我要找的答案。 我希望视频以特定尺寸开始,然后随着我调整浏览器大小(从桌面到 iPad/iPhone)而缩
我已经从 sql server 2005 切换到 mysql,这并不是一个真正的问题。 我对 sql server 中存在的 (n)varchar 有一个小问题。通常我用过: mapping.Map(
我必须使用自定义 odbc 驱动程序。 我需要作为连接字符串传递的只是 DSN。 我如何使用(流畅)nhibernate 做到这一点? FluentNHibernate.Cfg.Db 仅提供带有 DS
我无法找到我们网站上动态显示的弹出窗口。最初该元素处于以下 html 状态: 使用jquery的show和hide,div显示5秒,稍后隐藏。 在我的 Selenium 脚本中,我尝试使用以下语句等
我有一个 two/three基于屏幕尺寸的列布局。 如果窗口大小大于 1000比我需要遵循 3 column其他布局我需要遵循 two column布局。 我是用JS实现的,但是代码很乱。现在我想用
我有一个 Flutter 应用程序,随着时间的推移和添加的功能越来越多,它变得越来越笨拙。因此,是否有一些实用程序可以使其像 60FPS 一样流畅? 我知道这里有一些官方指南:https://docs
我在如何实现 $(window).smartresize() 上纠结了几个小时使我的 div 流畅的功能。 我使用了这个 theme 中的 javascript但是当我尝试自己实现它时,我的 div
当我尝试通过 canvas.getContext('2d') 和 canvas.getContext('webgl') 将相同的 PNG 文件加载到 Canvas 中时,发现与canvas2d相比,w
我有一个所有实体的基类: public class BaseClass { public int SomeProperty {get; set;} } public class SomeEnt
我正在从事一个对时间相当敏感的元素。任务是制作一个微型网站,用户可以通过他们的智能手机访问该网站,在那里他们可以访问许多电影。他们会扫描二维码(我知道他们已经死了,我没有计划这次事件)。并登陆这个网站
我们正在使用Entity Framework 5.0。和数据库MySQL。当我们尝试迁移时间时出现异常。 could not be created because the principal key
快速问题:如何将传递给shiny.fluent::Text函数的文本设置为粗体?更广泛地说,如何将样式选项传递给此函数?。在函数的帮助页面中,它是这样写的。但我不明白如何使用这个变量参数。。我试着在不
我是一名优秀的程序员,十分优秀!