我已经制作了一个自定义的UILabel类,我在框架的底部画了一条红线.红线显示但我无法显示文本.
#import <UIKit/UIKit.h>
@interface LetterLabel : UILabel {
}
@end
#import "LetterLabel.h"
@implementation LetterLabel
- (id)initWithFrame:(CGRect)frame {
if (self = [super initWithFrame:frame]) {
// Initialization code
}
return self;
}
- (void)drawRect:(CGRect)rect {
CGContextSetLineWidth(UIGraphicsGetCurrentContext(), 2.0);
CGContextSetRGBStrokeColor(UIGraphicsGetCurrentContext(), 1.0, 0.0, 0.0, 1.0);
CGContextBeginPath(UIGraphicsGetCurrentContext());
CGContextMoveToPoint(UIGraphicsGetCurrentContext(), 0.0, self.frame.size.height);
CGContextAddLineToPoint(UIGraphicsGetCurrentContext(), self.frame.size.width, self.frame.size.height);
CGContextStrokePath(UIGraphicsGetCurrentContext());
}
- (void)dealloc {
[super dealloc];
}
@end
Run Code Online (Sandbox Code Playgroud)
#import <UIKit/UIKit.h>
#import "Word.h"
@interface WordView : UIView {
Word *gameWord;
}
@property (nonatomic, retain) Word *gameWord;
@end
@implementation WordView
@synthesize gameWord;
- (id)initWithFrame:(CGRect)frame …Run Code Online (Sandbox Code Playgroud) 我只是让我的keydown方法工作.但每按一次键,我都会发出哔哔声.我不知道什么是错的.用Google搜索了几个小时,所有人都说如果你有keyDown方法,你也应该实现acceptFirstResponder.这样做,它仍然无法正常工作.
#import <Cocoa/Cocoa.h>
#import "PaddleView.h"
#import "BallView.h"
@interface GameController : NSView {
PaddleView *leftPaddle;
PaddleView *rightPaddle;
BallView * ball;
CGPoint ballVelocity;
int gameState;
int player1Score;
int player2Score;
}
@property (retain) IBOutlet PaddleView *leftPaddle;
@property (retain) IBOutlet PaddleView *rightPaddle;
@property (retain) IBOutlet BallView *ball;
- (void)reset:(BOOL)newGame;
@end
Run Code Online (Sandbox Code Playgroud)
#import "GameController.h"
#define GameStateRunning 1
#define GameStatePause 2
#define BallSpeedX 0.2
#define BallSpeedY 0.3
#define CompMoveSpeed 15
#define ScoreToWin 5
@implementation GameController
@synthesize leftPaddle, rightPaddle, ball;
- (id)initWithCoder:(NSCoder *)aDecoder {
self = [super initWithCoder:aDecoder]; …Run Code Online (Sandbox Code Playgroud) 我以为我得到了可可内存管理的支持,但我显然还有很多需要学习的东西.
看看我写的这堂课:
Word.h
#import <UIKit/UIKit.h>
@interface Word : NSObject {
NSString *word;
NSMutableArray *wordArray;
}
@property (nonatomic ,retain) NSString *word;
@property (nonatomic ,retain) NSMutableArray *wordArray;
@end
Run Code Online (Sandbox Code Playgroud)
Word.m
#import "Word.h"
@implementation Word
@synthesize word, wordArray;
- (void)setWord:(NSString *)aWord {
NSMutableArray *newValue = [[NSMutableArray alloc] init];
self.wordArray = newValue;
[newValue release];
for (int i = 0 ;i < [aWord length] ;i++) {
NSString *character = [[NSString alloc] init];
character = [NSString stringWithFormat:@"%C",[aWord characterAtIndex:i]];
[wordArray addObject:character];
//[character release];
}
}
- (void)dealloc { …Run Code Online (Sandbox Code Playgroud) var str = "Stavsnäs"
var strWithoutWierdCharacters = str.stringByReplacingOccurrencesOfString("ä", withString: "ä", options: NSStringCompareOptions.LiteralSearch, range:nil)
Run Code Online (Sandbox Code Playgroud)
在Swift中必须有更好的方法吗?