QAView 0.1.1

QAView 0.1.1

TestsTested
LangLanguage Obj-CObjective C
License MIT
ReleasedLast Release Feb 2016

Maintained by belakva.




QAView 0.1.1

QAView represents 2 UIScrollViews:_questionsScroller & _answersScroller populated with 2 arrays: _questions & _answers respectively. When a question is tapped, it becomes active and ready to be connected to answers. Use this pod whenever you have to visualize dependencies in between elements of 2 arrays.

Requirements

  • iOS 7 - if install manually
  • iOS 8 - if use CocoaPods

Installation

Manual

Just drag and drop the QAView/QAView folder into your project.

Usage

Set up

Set up is easy as

_qaView = [[QAView alloc] initWithFrame:self.view.frame
                                  questions:@[@"Frank",
                                              @"Jason"]
                                    answers:@[@"Anna",
                                              @"Maria",
                                              @"Jessica"]];

You can set highlight colors

_qaView.colors = @[[UIColor greenColor], [UIColor purpleColor]];

If not set, highlight colors are generated automatically with hue step = (360./[questions count])/360.

You can set inactive color

_qaView.inactiveColor = [UIColor redColor];

Default is gray with lightness = 0.89

Set logic scheme

_qaView.canUseOneAnswerToSeveralQuestions = NO; //Defaults to YES
_qaView.canUseSeveralAnswersToOneQuestion = NO; //Defaults to YES

Delegate

You can set whatever you like as QAView delegate

_qaView.delegate = self;

To do this, adopt <QAViewDelegate> protocol. It has following @optional methods:

- (void)didRecieveTapInAnswerView:(QAItemView *)view;
- (void)didRecieveTapInQuestionView:(QAItemView *)view;

- (void)answersScrollerDidScroll:(QAScrollView *)scrollView;
- (void)questionsScrollerDidScroll:(QAScrollView *)scrollView;

- (QAItemView *)itemViewForAnswerAtIndex:(NSUInteger)index;     //cutom cell set up
- (QAItemView *)itemViewForQuestionAtIndex:(NSUInteger)index;   //custom cell set up

- (NSUInteger)numberOfAnswers;
- (NSUInteger)numberOfQuestions;

Custom cell set up

Following cell (QAItemView) propeties are designed for custom set up:

@property (strong, nonatomic) UIColor* highlightColor;
@property (strong, nonatomic) UIColor* inactiveColor;;
@property (strong, nonatomic) UILabel* textLabel;

@property (nonatomic) CFTimeInterval connectingAnimationDuration;
@property (nonatomic) CGFloat connectingLineWidth;
@property (nonatomic) BOOL useGradients;
@property (nonatomic) BOOL useCirclesOnLineConnectionPoints;
@property (nonatomic) BOOL useCurvesInConnection;

Edit them when initilizing a QAItemView in itemViewForAnswerAtIndex: / itemViewForQuestionAtIndex:.

Important

When initilizing cell with [[QAItemView alloc] init] in itemViewForAnswerAtIndex: / itemViewForQuestionAtIndex:, do not set or retrieve its' frame, as the frame will be set automatically right after this method is called.

FOR MANUAL FRAME SET UP, use following initilizer:

- (id)initWithFrame:(CGRect)frame text:(NSString*)text
                                 index:(NSInteger)index
                        totalQuestions:(NSInteger)totalQuestions
                         inactiveColor:(UIColor*)inactiveColor
                           activeColor:(UIColor*)activeColor
                            asQuestion:(BOOL)asQuestion

For formula, used for automatic cell frame calculation check Example project.

Retrieving data

Call methods of QAView

- (NSIndexSet*)connectedQuestionsIndexesForAnswerAtIndex:(NSUInteger)index;
- (NSIndexSet*)connectedAnswersIndexesForQuestionAtIndex:(NSUInteger)index;

Author

Nikita Borisov https://twitter.com/nikita_kerd

License

QAView is available under the MIT license. See the LICENSE file for more info.