我正在尝试创建一个可以始终垂直滚动的类(ScrollableView:UIScrollView),类似于TableView.我已经硬编码了一个常量值来添加到内容大小,以便它始终可以滚动.但是出于某些奇怪的原因,当值为1时它将不起作用; 它只有在值为4或更大时才有效.
- (id)initWithFrame:(CGRect)frame {
self = [super initWithFrame:frame];
if (self) {
self.contentSize = CGSizeMake(frame.size.width, frame.size.height+1);
self.scrollEnabled = YES;
}
return self;
}
Run Code Online (Sandbox Code Playgroud)
还有另一种方法吗?这似乎不是正确的方法.
我有一个多行标签,其中包含以下文本:
许多文字在这里·$$$$
由于开头的文本是自由格式的,因此有时换行最终看起来像这样:
Lots of text here · $$$
$
Run Code Online (Sandbox Code Playgroud)
如何防止这种情况发生?我希望它看起来像这样:
Lots of text here ·
$$$$
Run Code Online (Sandbox Code Playgroud)
我尝试了每一个lineBreakMode都没有用。自动换行不起作用,因为它不会将$$$$作为单词处理。
我写了一个看起来像这样的函数:
- (void)changeText:(NSUInteger)arrayIndex;
Run Code Online (Sandbox Code Playgroud)
我们只是说这是Label类中的一个方法.假设我有一个Label对象数组.我把这个函数称为:
[[labels objectAtIndex:0] changeText:1];
Run Code Online (Sandbox Code Playgroud)
或者像这样:
NSUInteger index = 1;
[[labels objectAtIndex:0] changeText:index];
Run Code Online (Sandbox Code Playgroud)
为什么它会给我警告:Passing argument 1 of 'changeText:' makes pointer from integer without a cast?代码执行正常.
*编辑*
以这些方式调用函数不会发出警告:
[[labels objectAtIndex:0] changeText:0]; //arrayIndex is 0
Label *object = [labels objectAtIndex:0];
[object changeText:1];
Run Code Online (Sandbox Code Playgroud)