我需要以编程方式创建按钮,用于正常和突出显示的状态以及文本.我无法使用Interface Builder构建它,因为我需要在a上创建按钮UIScrollView.这是我到目前为止的代码:
- (void)loadView {
CGRect fullScreenRect=[[UIScreen mainScreen] applicationFrame];
scrollView=[[UIScrollView alloc] initWithFrame:fullScreenRect];
scrollView.contentSize=CGSizeMake(320,960);
UIImageView *tempImageView2 = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"image.jpeg"]];
UIImage * buttonImage = [UIImage imageNamed:@"contentlist_active.png"];
self.view=scrollView;
[scrollView addSubview:tempImageView2];
btn = [UIButton buttonWithType:UIButtonTypeCustom];
btn.frame = CGRectMake(22, 100, 277, 32);
[btn setImage:buttonImage forState:UIControlStateNormal];
[btn setTitle:@"hello world" forState:UIControlStateNormal];
[btn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
[scrollView addSubview:btn];
}
Run Code Online (Sandbox Code Playgroud)
但是按钮上的文字没有显示.如果我注释掉了setImagefor button,则文本显示完美,否则不显示.我可以同时同时拥有文字和图片吗?
有没有办法让SKSpriteNode圆形走投无路?我正在尝试用颜色填充的SKSpriteNode创建一个Tile likesqaure块:
SKSpriteNode *tile = [SKSpriteNode spriteNodeWithColor:[UIColor colorWithRed:0.0/255.0
green:128.0/255.0
blue:255.0/255.0
alpha:1.0] size:CGSizeMake(30, 30)];
Run Code Online (Sandbox Code Playgroud)
如何围绕走投无路?
谢谢!
我是UIButton的子类,我想要的是将按钮类型设置为Round Rect.
Button.h
@interface Button : UIButton {}
- (void)initialize;
@end
Run Code Online (Sandbox Code Playgroud)
Button.m
@implementation Button
- (id)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self) {
[self initialize];
}
return self;
}
-(id)initWithCoder:(NSCoder *)aDecoder {
self = [super initWithCoder:aDecoder];
if(self){
[self initialize];
}
return self;
}
- (void)initialize
{
self.titleLabel.font = [UIFont systemFontOfSize:20];
self.titleLabel.textColor = [UIColor redColor];
self.titleLabel.textAlignment = UITextAlignmentCenter;
//[UIButton buttonWithType:UIButtonTypeRoundedRect];
}
@end
Run Code Online (Sandbox Code Playgroud)
在这里我尝试[UIButton buttonWithType:UIButtonTypeRoundedRect]但它不起作用.任何人都可以建议如何使其工作?
我在之前的许多文章中都知道,不推荐使用Subclassing UIButton,但事实上在Developer's Docs中没有提及NOT子类化它.
所以这是我需要在iOS上完成的任务:
在图像上显示用户的当前位置,如下所示:

是的,就像这张图片!
一看一眼就会注意到的事情很少.它倾斜了.它的标题是关闭.你可以看到地平线..!
可以说,
但那就是任务,我需要在这些图像上显示用户位置.就像在"谷歌地球"中一样.
任何人都可以帮我完成这项任务吗?
谢谢大家.:)
我正在SpriteKit上开发像Scrabble这样的游戏,并且一直停留在Scoble和Scrolling Scrabble Board上.首先让我解释游戏背后的工作:在我的GameScene上我有:
一个名为GameBoard Layer(名为NAME_GAME_BOARD_LAYER)的SKNode子类,包含以下子项:
A SKNode subclass for Scrabble Board named NAME_BOARD.
A SKNode subclass for Letters Tile Rack named NAME_RACK.
Run Code Online (Sandbox Code Playgroud)
Letters Tiles从Tile Rack中挑选并放入Scrabble Board.
这里的问题是,我需要模仿UIScrollView可以实现的缩放和滚动,我认为不能在SKNode上添加.我需要模仿的功能是:
这是我用于缩放的代码,使用UITapGestures:
在我的GameScene.m中
- (void)didMoveToView:(SKView *)view {
UITapGestureRecognizer *tapGesture = [[UITapGestureRecognizer alloc] initWithTarget:self
action:@selector(handleTapGesture:)];
tapGesture.numberOfTapsRequired = 2;
tapGesture.numberOfTouchesRequired = 1;
[self.scene.view addGestureRecognizer:tapGesture];
}
- (void)handleTapGesture:(UITapGestureRecognizer*)recognizer {
if ([self childNodeWithName:NAME_GAME_BOARD_LAYER]) {
GameBoardLayer *gameBoardLayer = (GameBoardLayer*)[self childNodeWithName:NAME_GAME_BOARD_LAYER];
SKNode *node = [Utils nodeAt:[recognizer locationInView:self.view]
withName:NAME_BOARD
inCurrentNode:gameBoardLayer];
if ([node.name isEqualToString:NAME_BOARD]) {
[gameBoardLayer handleDoubleTap:recognizer];
} …Run Code Online (Sandbox Code Playgroud) 任务是显示手机麦克风中的语音幅度,并显示如下幅度:

有人可以指导我如何实现这一目标.
感谢大家.
我创建与动画GIF文件NSArray的UIImage.并将其保存在NSDocumentDirectoryiPhone的相册中.
我面临的问题是,当我在Email Composer或iMessage中打开保存的GIF时,它会动画很好.但是当我通过Twitter分享它时,它没有动画.我尝试通过iPhone上的Twitter应用程序分享并看到一个有趣的事情(下面的ScreenShot)我使用Safari从不同网站下载的GIF在GIF的左上角显示了一个标签'GIF'.虽然我保存的GIF没有.这可能是什么问题?任何人都可以指导我.

以下是创建GIF文件的代码:
float delay = 1.0/15.0; // 15 FPS
NSDictionary *prep = @{
(__bridge id)kCGImagePropertyGIFDictionary: @{
(__bridge id)kCGImagePropertyGIFDelayTime: @(delay)
}
};
// static NSUInteger kFrameCount = 16;
NSDictionary *fileProperties = @{
(__bridge id)kCGImagePropertyGIFDictionary: @{
(__bridge id)kCGImagePropertyGIFLoopCount: @0 // 0 means loop forever
}
};
CFURLRef url = (__bridge CFURLRef)[NSURL fileURLWithPath:path];
CGImageDestinationRef dst = CGImageDestinationCreateWithURL(url, kUTTypeGIF, [images count], nil);
CGImageDestinationSetProperties(dst, (__bridge CFDictionaryRef)fileProperties);
for (int i=0;i<[images count];i++)
{
//load anImage from array
UIImage * …Run Code Online (Sandbox Code Playgroud) 我正在开发一个应用程序,它需要使用分辨率高于(2000 x 2000)的图像,以达到文本清晰度.
我有一个背景图像,我需要在其上显示具有相同分辨率的叠加图像.叠加的数量是可变的,从2到30.
在使用UIImage加载图像时,每个像素需要4个字节,因此如果一个图像的分辨率为3000x3000,则需要最多34 MB的内存,15 MB的2000 x 2000.
这就是问题出现的问题,应用程序在3GS上加载4-5张图像后崩溃,在iPhone 4上加载11-13张图像.
需要将叠加层准确放置在背景图像上.它们就像我们在谷歌地图流量叠加层中所拥有的那样.这并不排除平铺,但使任务相对复杂.
我该如何处理这个问题?
我正在为iOS开发一个phonegap应用程序.当我双击屏幕底部时,主屏幕会向上滑动.这仅在纵向模式下发生.
我试过禁用滚动..但这没有奏效.这是我的HTML代码:
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, minimum-scale=1.0, maximum-scale=1.0 " />
<body>
<div class="mainScreenContent" align="center">
<table>
<form>
<tbody>
<tr >
<td>
<button type="submit" class="largeButton grayGradientEffect">Button 1</button>
</td>
</tr>
<tr>
<td >
<button type="submit" class="largeButton grayGradientEffect" onclick="">Button 2</button>
</td>
</tr>
</tbody>
</form>
</table>
</div>
</body>
Run Code Online (Sandbox Code Playgroud)
这是屏幕截图:
这就是主屏幕的样子:

这是双击底部后的样子:

谢谢大家的帮助.
Facebook SDK 3.2
我需要在使用faceboook登录后在Facebook上发布一个墙贴.
这是我正在使用的代码:
在这里,我打开了Facebook会议:
- (IBAction)FBSignup:(id)sender {
[[AppDelegate sharedObject] openSession:^(FBSession *session, FBSessionState state, NSError *error) {
[self sessionStateChanged:session state:state error:error];
}];
}
Run Code Online (Sandbox Code Playgroud)
在状态变化,我用[self populateUserDetails]填充数据,然后尝试在Facebook墙上发布[self postOnFB],但Facebook墙上没有帖子.
- (void)sessionStateChanged:(FBSession *)session
state:(FBSessionState) state
error:(NSError *)error
{
switch (state) {
case FBSessionStateOpen:
[self populateUserDetails];
[self postOnFB];
break;
case FBSessionStateClosed:
case FBSessionStateClosedLoginFailed:
[FBSession.activeSession closeAndClearTokenInformation];
break;
default:
break;
}
[[NSNotificationCenter defaultCenter]
postNotificationName:SCSessionStateChangedNotification
object:session];
if (error) {
UIAlertView *alertView = [[UIAlertView alloc]
initWithTitle:@"Error"
message:error.localizedDescription
delegate:nil
cancelButtonTitle:@"OK"
otherButtonTitles:nil];
[alertView show];
}
} …Run Code Online (Sandbox Code Playgroud) ios ×10
iphone ×8
ios5 ×2
ipad ×2
sprite-kit ×2
xcode ×2
cordova ×1
facebook ×1
geolocation ×1
gif ×1
html5 ×1
image ×1
ios4 ×1
iphone-3gs ×1
iphone-4 ×1
objective-c ×1
scroll ×1
subclass ×1
uibutton ×1
uiscrollview ×1
xcode4.2 ×1