private func setTitle(title:String, subtitle:String, animate: Bool) -> UIView {
let titleLabel = UILabel(frame: CGRect(x:0, y:-5, width:0, height:0))
titleLabel.backgroundColor = UIColor.clear
titleLabel.textColor = UIColor.gray
titleLabel.font = UIFont.boldSystemFont(ofSize: 15)
titleLabel.text = title
titleLabel.adjustsFontSizeToFitWidth = true
let subtitleLabel = UILabel(frame: CGRect(x:0, y:18, width:0, height:0))
subtitleLabel.backgroundColor = UIColor.clear
subtitleLabel.textColor = UIColor.black
subtitleLabel.font = UIFont.systemFont(ofSize: 12)
subtitleLabel.text = subtitle
subtitleLabel.adjustsFontSizeToFitWidth = true
let titleView = UIView(frame: CGRect(x:0, y:0, width:max(titleLabel.frame.size.width, subtitleLabel.frame.size.width), height:30))
let titleViewTapGesture = UITapGestureRecognizer(target: self, action: #selector(titleViewTapped(sender:)))
titleView.addGestureRecognizer(titleViewTapGesture)
titleView.addSubview(titleLabel)
if animate{
subtitleLabel.alpha = 0.0 …Run Code Online (Sandbox Code Playgroud) 我正在尝试在UILabel. 这个问题之前已经被问过很多次了,答案很简单:
override func awakeFromNib() {
super.awakeFromNib()
let fontSize: CGFloat = 24
let descriptor = UIFont
.systemFont(ofSize: 24)
.fontDescriptor
.addingAttributes([
UIFontDescriptor.AttributeName.featureSettings: [
UIFontDescriptor.FeatureKey.featureIdentifier: kLowerCaseType,
UIFontDescriptor.AttributeName.featureSettings: kLowerCaseSmallCapsSelector
]
])
titleLabel.font = UIFont(descriptor: descriptor, size: fontSize)
titleLabel.text = "Welcome"
}
Run Code Online (Sandbox Code Playgroud)
然而,这段代码不起作用,我不明白为什么。我有几个想法:
UILabel.text。然而,使用该UILabel.attributedText属性并不能解决问题。UILabel根本不支持小型大写字体。我尝试过UITextView,但结果是一样的。还有什么我可能想念的吗?
我正在尝试构建一个 UILabel。
但我想在这个标签弹出时制作动画
我应该在哪里为标签设置动画?
这是我的代码
static func setupView(view: UIView){
let networkStatusView = UILabel(frame: CGRect(x: 0, y: 40, width: view.bounds.width, height:50))
networkStatusView.tag = 20
networkStatusView.text = "offline"
networkStatusView.font = UIFont.boldSystemFont(ofSize: 18)
networkStatusView.translatesAutoresizingMaskIntoConstraints = false
networkStatusView.textAlignment = .center
networkStatusView.backgroundColor=UIColor.green
networkStatusView.layer.borderColor = UIColor.white.cgColor
UIView.animate(withDuration: 0.5) {
view.addSubview(networkStatusView)
}
view.layoutIfNeeded()
}
Run Code Online (Sandbox Code Playgroud) 我正在尝试创建一个自定义 UILabel,其中文本颜色为红色。这是我尝试过的,但这些都不起作用:
class CustomLabel: UILabel {
override func awakeFromNib() {
UILabel.appearance().textColor = UIColor.blue
textColor = UIColor.blue
}
}
Run Code Online (Sandbox Code Playgroud) 我正在使用一个简单的函数通过标签向用户显示消息.功能如下:
-(void) showMessage:(NSString*) message
{
Message.text = message;
[message release];
}
Run Code Online (Sandbox Code Playgroud)
如果我从主线程调用此函数,则没有内存泄漏.但是,如果我从一个单独的线程调用此函数,则一旦调用该函数,仪器监视器就会显示16字节的内存泄漏.如果我注释掉函数调用,则看不到泄漏.有谁知道为什么?我正在使用iPhone SDK 3.0.仪器监视器不指向我的任何功能来指示泄漏.它只显示UILabel的一个或两个函数.
几天来一直有这个问题,似乎无法找到解决方案.这可能是一些非常基本的东西,但仍然无法提出解决方案.
我有一堆标签嵌套在表格视图单元格中,带有编辑导航控制器按钮,可以转到另一个表格视图.此表视图具有将数据存储到SQLite数据库的文本字段.标签从数据库返回某些值.现在这部分完美无缺.但是,当我更新文本字段并导航回标签时,标签不会更新,如果我滚动表格以使修改后的单元格不在视图中,那么它会更新,所以认为问题是单元格仍然具有旧值缓存,只有在它出列时才释放它.
部分代码:(至少我认为这是重要的,因为这是创建单元格的地方)
欢迎任何帮助.谢谢
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = @"ContactsDetailCell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
}
// Configure the cell.
Run Code Online (Sandbox Code Playgroud)
int row = [indexPath row]; int section = [indexPath section];
NSDictionary*resultSet = [sqliteManager queryRow:[NSString stringWithFormat:@"SELECT*FROM contacts WHERE id =%d;",contactsId]];
switch(section){case 0:switch(row){case 0:cell.textLabel.text = @"Name:";
UILabel *nameLabel = [[UILabel alloc] initWithFrame: CGRectMake(90, 10, 200, 25)];
nameLabel.text = [resultSet objectForKey:@"name"];
nameLabel.textColor = [UIColor blackColor]; …Run Code Online (Sandbox Code Playgroud) 我尝试更改读取并从UILabel更改位置.这个UILabel是在Interface Builder中创建的,现在我想在MainVieController类中调用一个方法时读取并更改另一个类中的位置.
但我怎么能这样做,我已经阅读了几个论坛,但我不能让它工作.这里还有一些示例代码.我希望有人可以帮助我.
MainViewController.h
#import <UIKit/UIKit.h>
@class NewClass;
@interface MainViewController : UIViewController {
UILabel *daLabel;
}
@property (nonatomic, retain) IBOutlet UILabel *daLabel;
@end
Run Code Online (Sandbox Code Playgroud)
MainViewController.m
#import "MainViewController.h"
#import "NewClass.h"
@implementation MainViewController
@synthesize daLabel;
- (void)viewDidLoad {
[super viewDidLoad];
NewClass *anotherClass = [[NewClass alloc] init];
[anotherClass test];
}
@end
Run Code Online (Sandbox Code Playgroud)
NewClass.h
#import <Foundation/Foundation.h>
@class MainViewController;
@interface NewClass : NSObject {
}
@end
Run Code Online (Sandbox Code Playgroud)
NewClass.m
#import "NewClass.h"
#import "MainViewController.h"
@implementation NewClass
- (void)test {
MainViewController *MainController = [[MainViewController alloc] init];
CGRect labelPosition = MainController.daLabel.frame;
NSLog(@"POSITION: …Run Code Online (Sandbox Code Playgroud) 当我使用这个自定义的UIView来显示一行3 x UILabels时,我有点想看看为什么,当我看到红色的轮廓为框架时,我在框架内看不到任何东西.那就是标签没有出现,我设置的UILabels的黑色边框也没有出现.
谁能在这里发现问题?
#import <UIKit/UIKit.h>
@interface LabelRowView : UIView {
UILabel *_dateLabel;
UILabel *_titleLabel;
UILabel *_locationLabel;
}
@property (nonatomic, retain) UILabel *dateLabel;
@property (nonatomic, retain) UILabel *titleLabel;
@property (nonatomic, retain) UILabel *locationLabel;
- (void)setFont:(UIFont *)newFont;
- (void)setDataWithDate:(NSString*)dateStr AndTitle:(NSString*)titleStr AndLocation:(NSString*)locationStr;
@end
// ==============================================================
@implementation LabelRowView
@synthesize dateLabel = _dateLabel;
@synthesize titleLabel = _titleLabel;
@synthesize locationLabel = _locationLabel;
- (void)setDefaultsForLabel:(UILabel*)label {
label.layer.borderColor = [UIColor blackColor].CGColor;
label.layer.borderWidth = 1.0;
label.textAlignment = UITextAlignmentLeft;
label.lineBreakMode = UILineBreakModeTailTruncation;
label.opaque = YES; // TODO: put back …Run Code Online (Sandbox Code Playgroud) 我的UILabel怎么能像TableView的UITableViewStyleGrouped一样?
uilabel ×10
iphone ×5
ios ×4
objective-c ×3
swift ×2
uiview ×2
class ×1
core-text ×1
label ×1
memory-leaks ×1
position ×1
swift4 ×1
typography ×1
uitableview ×1