FORUMS PROFESSIONNELS
WINDEV
,
WEBDEV
et
WINDEV Mobile
Accueil
|
Messages récents
|
Connexion
|
Déconnexion
|
Français
Accueil
→
WINDEV Mobile 2024
→
Toast in iOS
Toast in iOS
Débuté par adrianoboller, 17 nov. 2014 13:14 - 2 réponses
Connectez-vous…
adrianoboller
#1
Membre enregistré
3 657 messages
Popularité : +175 (223 votes)
Posté le 17 novembre 2014 - 13:14
#import
<
UIKit
/
UIKit.h
>
#import
<
QuartzCore
/
QuartzCore.h
>
#import
<
MediaPlayer
/
MediaPlayer.h
>
void IOS
(
)
{
}
//////////////////////////////////////////////////
// Classes
//////////////////////////////////////////////////
#define FONT_SIZE
14
#define LEFT_RIGHT_PADDING
14
#define TOP_BOTTOM_PADDING
10
#define BOTTOM_MARGIN
200
#define BACKGROUND_COLOR darkGrayColor
#define FADE_IN_DURATION
0.4
#define FADE_OUT_DURATION
0.3
#define DELAY
2
#define MAX_CHAR_LINHA
30
#define MAX_LENGTH_LABEL
300
#define LEFT_RIGTH_BORDER_INTERN
10
#define LEFT_RIGTH_BORDER_EXTERN
20
#define TOP_BOTTOM_BORDER_INTERN
10
#define SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO
(v)
(
[
[
[
UIDevice currentDevice
]
systemVersion
]
compare
:
v options
:
NSNumericSearch
] !
=
NSOrderedAscending
)
#define SYSTEM_VERSION_LESS_THAN
(v)
(
[
[
[
UIDevice currentDevice
]
systemVersion
]
compare
:
v options
:
NSNumericSearch
] =
=
NSOrderedAscending
)
#define iOS7_0
@
"7.0"
// Toast
@
interface WDToast
:
NSObject
// Message
@
Property
(
nonatomic
,
strong
)
NSString
*
Message
;
// Durée
@
Property
(
nonatomic
)
int
Delai
;
// Champ libellé
@
Property
(
nonatomic
,
strong
)
UILabel
*
label
;
+ (
WDToast
*
)
toastWithMessage
:
(
NSString
*
)
msg delay
:
(
int
)
n
Delai
;
// Affiche le toast
- (
void
)
showOnView
:
(
UIView
*
)
mainView
;
@
END
// Implémentation de l'interface WDToast
@
implementation WDToast
{
CGRect rect
;
}
+ (
WDToast
*
)
toastWithMessage
:
(
NSString
*
)
msg delay
:
(
int
)
n
Delai
;
{
WDToast
*
t
= [
[
WDToast alloc
]
init
]
;
t.message
=
msg
;
t.Delai
=
n
Delai
;
//Resolucao
float
x
Label
;
float yLabel
;
float wScreen
;
float
h
Screen
;
float
h
Lablel
;
float wLabel
;
int
countLines
=
0
;
CGSize sz
= [
UIScreen mainScreen
]
.
bounds.size
;
wScreen
=
sz
.width
;
h
Screen
=
sz
.height
;
UIFont
*
font
= [
UIFont systemFontOfSize
:
FONT_SIZE
]
;
// version < 7.0
IF
(
SYSTEM_VERSION_LESS_THAN
(
iOS7_0
)
) {
//Adriano suprime warning//
#pragma clang diagnostic
Push
#pragma clang diagnostic ignored
"-Wdeprecated-declarations"
//Adriano suprime warning//
CGSize withinSize
=
CGSizeMake
(
wScreen
-
LEFT_RIGTH_BORDER_EXTERN
-
LEFT_RIGTH_BORDER_INTERN
,
FLT_MAX
)
;
CGSize size
= [
msg sizeWithFont
:
font constrainedToSize
:
withinSize lineBreakMode
:
NSLineBreakByWordWrapping
]
;
wLabel
=
size.width
+
LEFT_RIGTH_BORDER_INTERN
;
h
Lablel
=
size.height
+
TOP_BOTTOM_BORDER_INTERN
;
}
ELSE IF
(
SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO
(
iOS7_0
)
) {
CGSize size2
= [
msg boundingRectWithSize
:
CGSizeMake
(
wScreen
-
LEFT_RIGTH_BORDER_EXTERN
-
LEFT_RIGTH_BORDER_INTERN
,
MAXFLOAT
)
options
:
NSStringDrawingUsesLineFragmentOrigin
attributes
:
@
{
NSFontAttributeName
:
font
}
// version >= 7.0
context
:
nil
]
.
size
;
wLabel
=
size2.width
+
LEFT_RIGTH_BORDER_INTERN
;
h
Lablel
=
size2.height
+
TOP_BOTTOM_BORDER_INTERN
;
}
ELSE
{
countLines
= (
(
[
msg
Length
]
)
/
MAX_CHAR_LINHA
)
+
1
;
IF
(
countLines
>
1
)
{
wLabel
=
MAX_LENGTH_LABEL
;
}
ELSE
{
wLabel
= (
[
msg
Length
] *
8
) +
FONT_SIZE
;
}
}
;
countLines
=
30
;
//Meio do iphone 3 e 4 = W: 160 e H: 240
x
Label
= (
wScreen
/
2
) - (
wLabel
/
2
)
;
yLabel
= (
h
Screen
/
2
)
;
//Desenha retangulo do Toast
CGRect rect
=
CGRectMake
(
x
Label
,
yLabel
,
wLabel
,
h
Lablel
)
;
t.label
= [
[
UILabel alloc
]
initWithFrame
:
rect
]
;
t.label.text
=
msg
;
t.label.textColor
= [
UIColor whiteColor
]
;
t.label.font
= [
UIFont systemFontOfSize
:
FONT_SIZE
]
;
t.label.textAlignment
=
NSTextAlignmentCenter
;
t.label.backgroundColor
= [
UIColor BACKGROUND_COLOR
]
;
t.label.numberOfLines
=
countLines
;
RETURN
t
;
}
- (
void
)
showOnView
:
(
UIView
*
)
view
{
[
self.label setAlpha
:
0
]
;
[
view addSubview
:
self.label
]
;
[
UIView animateWithDuration
:
FADE_IN_DURATION
animations
:
^
{
[
self.label setAlpha
:
1
]
;
}
completion
:
^
(
BOOL finished
) {
[
UIView animateWithDuration
:
FADE_OUT_DURATION
delay
:
self.Delai
options
:
0
animations
:
^
{ [
self.label setAlpha
:
0
]
; }
completion
:
^
(
BOOL finished
) {
}
]
;
}
]
;
}
@
END
Signaler
0
0
adrianoboller
#2
Membre enregistré
3 657 messages
Popularité : +175 (223 votes)
Posté le 17 novembre 2014 - 13:14
void IOS_ToastAffiche
(
NSString
*
s
Message
,
void
*
pcl
View
,
int
n
Delai
)
{
WDToast
*
pcl
Toast
= [
WDToast toastWithMessage
:
s
Message delay
:
n
Delai
]
;
[
pcl
Toast showOnView
:
(
UIView
*
)
pcl
View
]
;
}
Signaler
0
0
jbarker
#3
Membre enregistré
96 messages
Popularité : +1 (1 vote)
Posté le 11 mai 2015 - 23:54
bonjour, ne fonctionne pas chez moi une astuce ?
j'ai remplacé
void IOS(){}
par
void IOS_ToastAffiche(NSString *sMessage, void *pclView, int nDelai)
{
WDToast *pclToast = [WDToast toastWithMessage:sMessage delay:nDelai];
[pclToast showOnView:(UIView *)pclView];
}
mais pas bon
Signaler
0
0
→ Revenir à WINDEV Mobile 2024
WINDEV 2024
WEBDEV 2024
WINDEV Mobile 2024
WINDEV (précédentes versions)
WEBDEV (précédentes versions)
WINDEV Mobile (précédentes versions)
Etats & Requêtes
Hors-sujet
Outils
Français
English
Español
Portuguesa
Fermer cette fenêtre
Type de recherche
Uniquement les sujets
Tous les messages
Période de recherche
Date indifférente
Moins d'une heure
Moins de 24 heures
Moins d'une semaine
Moins d'un mois
Moins d'un an
Annuler
Aperçu de votre message
Ajouter une image
Importer une image depuis une URL
Envoyer une image depuis un fichier de votre disque
Déposez ici un fichier ou cliquez sur "Parcourir..."
ou
Annuler
0%
WLangage
SQL
XML, HTML
JAVA, Javascript
Texte