小编Osc*_*car的帖子

自定义UILabel不显示文本

我已经制作了一个自定义的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)

cocoa-touch objective-c quartz-graphics uiview

7
推荐指数
1
解决办法
3872
查看次数

keyDown工作但我发出哔哔声

我只是让我的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)

cocoa objective-c first-responder

4
推荐指数
1
解决办法
1575
查看次数

记忆管理问题

我以为我得到了可可内存管理的支持,但我显然还有很多需要学习的东西.

看看我写的这堂课:

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)

cocoa memory-management class objective-c

2
推荐指数
1
解决办法
140
查看次数

在Swift中转换String的瑞典章程

var str = "Stavsnäs"
var strWithoutWierdCharacters = str.stringByReplacingOccurrencesOfString("ä", withString: "ä", options: NSStringCompareOptions.LiteralSearch, range:nil)
Run Code Online (Sandbox Code Playgroud)

在Swift中必须有更好的方法吗?

string swift

0
推荐指数
1
解决办法
575
查看次数