标签上没有显示空格后向字符串添加空格。我使用以下方法来获取它。我想在字符串之后添加空格,并且应该在标签上显示。
NSString *text = @"ABCD";
text = [text stringByAppendingString:@" "];
但是当我跑步时它只显示为“ABCD”。
我在tableviewcell上显示标签,我正在将文本对齐设置为右
答案 0 :(得分:0)
应该是
text=[text stringByAppendingString:@"\t"];
<强>更新强>
任何追加方法都会起作用,我想你需要一些空间试试这个
r.js
感谢。
答案 1 :(得分:0)
检查设计。我检查了你的代码和NSLog它。用于测试
<Style TargetType="{x:Type Button}">
<Setter Property="Background" Value="Orange"/>
<Style.Triggers>
<Trigger Property="IsMouseOver" Value="True">
<Setter Property="Background" Value="LightGray"/>
</Trigger>
</Style.Triggers>
</Style>
答案 2 :(得分:0)
添加了子类UILabel并添加了一个edgeInsets属性。
customLabel.h
#import <UIKit/UIKit.h>
@interface customLabel : UILabel
@property (nonatomic, assign) UIEdgeInsets edgeInsets;
@end
customLabel.m
#import "customLabel.h"
@implementation customLabel
- (id)initWithFrame:(CGRect)frame{
self = [super initWithFrame:frame];
if (self) {
self.edgeInsets = UIEdgeInsetsMake(0, 0, 0, 2);
}
return self;
}
- (void)drawTextInRect:(CGRect)rect {
[super drawTextInRect:UIEdgeInsetsInsetRect(rect, self.edgeInsets)];
}
@end
ViewController.m
title = [[customLabel alloc] initWithFrame:CGRectMake(75, 25, 200, 14)];
[title setTextColor:[UIColor whiteColor]];
[title setFont:[UIFont systemFontOfSize:14]];
[title setText:@"Text"];
[self.view addSubview:title];
答案 3 :(得分:0)
请试试这个
NSString *text = @"ABCD";
text = [text stringByAppendingString:@" "];
NSMutableAttributedString *string = [[NSMutableAttributedString alloc] initWithString:[NSString stringWithFormat:@"%@.", text]];
[string addAttribute:NSForegroundColorAttributeName value:[UIColor blackColor] range:NSMakeRange(0,string.length-1)];
[string addAttribute:NSForegroundColorAttributeName value:[UIColor clearColor] range:NSMakeRange(string.length-1,1)];
label.attributedText = string;
如果您想更改标签的文字颜色而不是更改:
[string addAttribute:NSForegroundColorAttributeName value:[UIColor blackColor] range:NSMakeRange(0,string.length-1)];
答案 4 :(得分:-1)
试试这个:
text = [NSString stringWithFormat:@"%@ ", text];
答案 5 :(得分:-1)
NSString *yourString = @"ABCD";
NSString *spaceString = @" ";
NSString *finalString = [NSString stringWithFormat:@"%@%@",yourString,spaceString];