这是我的代码
UIButton *btn = [UIButton buttonWithType:UIButtonTypeRoundedRect];
[btn setFrame:CGRectMake(0.0f, 0.0f, 100.0f, 100.0f)];
[btn setTitle:[NSString stringWithFormat:@"Button %d", i+1] forState:UIControlStateNormal];
[btn addTarget:self action:@selector(buttonPressed:) forControlEvents:UIControlEventTouchUpInside];
btn.titleLabel.frame = ???
Run Code Online (Sandbox Code Playgroud) 当我使用UITableViewCellStyleValue1时,我得到了一个长字符串的textLabel,并且不知何故,detailTextLabel从视图中被推出.
当我缩短textLabel文本时,我可以看到detailTextLabel的文本.
反正是否有限制textLabel的宽度在上面的样式,以便它将截断textLabel与它太长?
我的代码是:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:CellIdentifier] autorelease];
}
cell.textLabel.lineBreakMode = UILineBreakModeTailTruncation;
//---get the letter in each section; e.g., A, B, C, etc.---
NSString *alphabet = [self.currencyNameIndex objectAtIndex:[indexPath section]];
//---get all states beginning with the letter---
NSPredicate *predicate = [NSPredicate predicateWithFormat:@"SELF beginswith[c] %@", alphabet];
self.currencyList = [self.keyCurrencyName filteredArrayUsingPredicate:predicate];
if ([self.currencyList count] > 0)
{
NSString …
Run Code Online (Sandbox Code Playgroud) 我正在尝试复制Secret App的文本标签转换.有没有人最好的方法来接近它?
看起来他们每个字母都以明文开始,然后将其设置为灰色,然后是白色文本颜色.
以下是一些截图:
我以前遇到过这个问题,但是到目前为止我能够解决这个问题,基本上我正在创建一个自定义UI按钮,将其图像设置为uiimage,然后在我使用下面的代码之前有一个标签的按钮现在丢失了它的标签.我需要该标签,因为它是以编程方式在后面的代码中设置的.
NSString *imageName = [NSString stringWithFormat:kNameOfButtonimage ];
UIImage *image = [UIImage imageNamed:imageName];
[button setImage:image forState:UIControlStateNormal ];
Run Code Online (Sandbox Code Playgroud)
任何你可以借出的帮助都会非常感激.
-缺口
我有一个类文件,它是该类的子UICollectionViewController
类。在我的cellForItemAtIndexPath
方法中,我试图设置textLabel
的单元格。但是,textLabel
完成中没有选项。到目前为止,这是方法:
override func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell {
let cell = collectionView.dequeueReusableCellWithReuseIdentifier(reuseIdentifier, forIndexPath: indexPath) as UICollectionViewCell
// Configure the cell
cell.backgroundColor = cellColor ? UIColor.blueColor() : UIColor.orangeColor()
//cell.textLabel.text = "Text"???
switch indexPath.item {
case 0...5:
cellColor = true
case 6...13:
cellColor = false
default:
cellColor = true
}
}
Run Code Online (Sandbox Code Playgroud)
我该怎么做才能将其添加textLabel
到单元格中?
我有一个RSS提要阅读器应用程序,每个单元格从RSS提要苹果网站的XML中的元素中收集标题.现在标题很长,所以我想做的是使用以下方法增加每个单元格的大小:
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
return 80;
}
Run Code Online (Sandbox Code Playgroud)
使标题分成两行或多行并展开,但文字继续直行并切断.我怎样才能解决这个问题?
textlabel ×6
ios ×3
iphone ×3
uibutton ×2
uitableview ×2
app-secret ×1
cocoa-touch ×1
objective-c ×1
swift ×1
uiview ×1
xcode ×1