如何将图像添加到UIView?这是我到目前为止尝试的内容:
UIView *imageHolder = [[UIView alloc] initWithFrame:CGRectMake(40, 200, 280, 192)];
UIImage *image = [UIImage imageNamed:@"bloodymoon.jpg"];
[imageHolder addSubview:image]; // Error: Incompatible pointer types
[self.mainView addSubview:imageHolder];
Run Code Online (Sandbox Code Playgroud) 在我的应用程序中,我有两个UIViewControler(第一个和第二个)的UINavigationController.第一个视图控制器包含UITableView.当触摸表格的单元格时,推动第二视图控制器.我想要的是在第二个视图中将自定义文本设置为后退按钮.这是第二个视图中的代码.
- (void)viewDidLoad
{
[super viewDidLoad];
self.navigationItem.leftBarButtonItem =
[[[UIBarButtonItem alloc] initWithTitle:@"Go back"
style:UIBarButtonItemStyleBordered
target:nil
action:nil] autorelease];
}
Run Code Online (Sandbox Code Playgroud)
问题是后退按钮的文本已更改,但触摸按钮时第二个视图控制器未从堆栈中删除.
我正在使用UILabel来保存一些文字.我想要的是使用0.4的alpha而不是文本制作UILabel背景.怎么做到这一点?
我无法弄清楚为什么该视图占据整个屏幕.
在AppDelegate文件中
...
self.viewController = [[[ViewController alloc]init]autorelease];
[self.window setRootViewController:self.viewController];
self.window.backgroundColor = [UIColor whiteColor];
Run Code Online (Sandbox Code Playgroud)
..
在ViewController.m中
UIView *view = [[UIView alloc]initWithFrame:CGRectMake(30, 30, 30, 30)];
[view setBackgroundColor:[UIColor greenColor]];
self.view = view;
Run Code Online (Sandbox Code Playgroud)
当我运行应用程序时,屏幕完全是绿色的,而不是只有绿色的正方形.这有什么不对?
我希望代码每3秒显示一次"新版本",但事实并非如此.
Car.h
#import <Foundation/Foundation.h>
@interface Car : NSObject
-(void)displayVersion;
@end
Run Code Online (Sandbox Code Playgroud)
Car.m
#import "Car.h"
@implementation Car
-(void)displayVersion
{
NSLog(@"New version");
}
@end
Run Code Online (Sandbox Code Playgroud)
main.c中
#import <Foundation/Foundation.h>
#import "Car.h"
int main (int argc, const char * argv[])
{
@autoreleasepool
{
Car *ford = [[Car alloc]init];
[NSTimer scheduledTimerWithTimeInterval:3
target:ford
selector:@selector(displayVersion)
userInfo:nil
repeats:YES];
}
return 0;
}
Run Code Online (Sandbox Code Playgroud)
这有什么不对?
PS:我讨厌"你的帖子没有太多的背景来解释代码部分;请更清楚地解释你的场景"
我认为代码是问题的最佳解释!
我想只在数组已经不包含该对象时才将对象添加到数组中.如何在NSArray中对containsObject方法进行相反的操作?
这是我在应用程序中设置自定义字体的方法
[self.titleLabel setFont:[UIFont fontWithName:@"FontName" size:self.font.pointSize]];
Run Code Online (Sandbox Code Playgroud)
我不赞成使用字体。
如何解决呢?
//编辑
UIButtonCustom.h
#import <Foundation/Foundation.h>
@interface UIButtonCustom : UIButton
@end
Run Code Online (Sandbox Code Playgroud)
UIButtonCustom.m
-(void)awakeFromNib
{
[super awakeFromNib];
[self.titleLabel setFont:[UIFont fontWithName:@"FontName" size:self.font.pointSize]];
}
Run Code Online (Sandbox Code Playgroud) 假设我有一个UILabel涵盖应用程序整个窗口的内容.在此标签中显示不同长度的随机文本.是否可以根据文本长度更改文本字体大小?
我是Objective-C世界的新手.在研究一些iOS/Mac应用程序时我注意到的是,如果使用try -catch很少使用.例如,在Java中几乎一直使用它.为什么在Objective-C中不常见?